File tree Expand file tree Collapse file tree 2 files changed +49
-48
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +49
-48
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class Lesson12 {
4
4
5
- /**
6
- * Provide the solution to LeetCode 3062 here:
7
- * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8
- */
5
+ /**
6
+ * Provide the solution to LeetCode 3062 here:
7
+ * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8
+ */
9
+ public String gameResult (ListNode head ) {
10
+ int oddPoints = 0 ;
11
+ int evenPoints = 0 ;
9
12
10
- public String gameResult (ListNode head ) {
11
- int oddPoints = 0 ;
12
- int evenPoints = 0 ;
13
-
14
- for (ListNode current = head ; current != null && current .next != null ; current = current .next .next ) {
15
- if (current .val < current .next .val ) {
16
- oddPoints ++;
17
- } else if (current .val > current .next .val ) {
18
- evenPoints ++;
19
- }
20
- }
13
+ for (ListNode current = head ;
14
+ current != null && current .next != null ;
15
+ current = current .next .next ) {
16
+ if (current .val < current .next .val ) {
17
+ oddPoints ++;
18
+ } else if (current .val > current .next .val ) {
19
+ evenPoints ++;
20
+ }
21
+ }
21
22
22
- if (oddPoints > evenPoints ) {
23
- return "Odd" ;
24
- } else if (evenPoints > oddPoints ) {
25
- return "Even" ;
26
- } else {
27
- return "Tie" ;
28
- }
23
+ if (oddPoints > evenPoints ) {
24
+ return "Odd" ;
25
+ } else if (evenPoints > oddPoints ) {
26
+ return "Even" ;
27
+ } else {
28
+ return "Tie" ;
29
29
}
30
- }
30
+ }
31
+ }
Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson12 ;
2
2
3
3
/** Implement the below Stack by providing code for the class methods. */
4
- public class Stack {
5
- private ListNode top ;
4
+ public class Stack {
5
+ private ListNode top ;
6
6
7
- public Stack () {
8
- this .top = null ;
9
- }
7
+ public Stack () {
8
+ this .top = null ;
9
+ }
10
10
11
- public void push (int value ) {
12
- ListNode newNode = new ListNode (value );
13
- newNode .next = top ;
14
- top = newNode ;
15
- }
11
+ public void push (int value ) {
12
+ ListNode newNode = new ListNode (value );
13
+ newNode .next = top ;
14
+ top = newNode ;
15
+ }
16
16
17
- public int pop () {
18
- if (isEmpty ()) {
19
- throw new IllegalStateException ("Stack is empty" );
20
- }
21
- int value = top .val ;
22
- top = top .next ;
23
- return value ;
17
+ public int pop () {
18
+ if (isEmpty ()) {
19
+ throw new IllegalStateException ("Stack is empty" );
24
20
}
21
+ int value = top .val ;
22
+ top = top .next ;
23
+ return value ;
24
+ }
25
25
26
- public int peek () {
27
- if (isEmpty ()) {
28
- throw new IllegalStateException ("Stack is empty" );
29
- }
30
- return top .val ;
26
+ public int peek () {
27
+ if (isEmpty ()) {
28
+ throw new IllegalStateException ("Stack is empty" );
31
29
}
30
+ return top .val ;
31
+ }
32
32
33
- public boolean isEmpty () {
34
- return top == null ;
35
- }
33
+ public boolean isEmpty () {
34
+ return top == null ;
35
+ }
36
36
}
You can’t perform that action at this time.
0 commit comments