File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,23 @@ public class Lesson12 {
7
7
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8
8
*/
9
9
public String gameResult (ListNode head ) {
10
- return null ;
10
+
11
+ ListNode current = head ;
12
+ int evenTeam = 0 ;
13
+ int oddTeam = 0 ;
14
+ while (current != null ) {
15
+ if (current .val < current .next .val ) {
16
+ oddTeam ++;
17
+ } else if (current .val > current .next .val ) {
18
+ evenTeam ++;
19
+ }
20
+ current = current .next .next ;
21
+ }
22
+
23
+ if (evenTeam < oddTeam ) {
24
+ return "oddTeamwins" ;
25
+ } else if (evenTeam > oddTeam ) {
26
+ return "eveTeamwins" ;
27
+ } else return "tie" ;
11
28
}
12
29
}
Original file line number Diff line number Diff line change @@ -9,18 +9,22 @@ public Stack() {
9
9
}
10
10
11
11
public void push (int value ) {
12
- // Your code here
12
+ ListNode first = new ListNode (value );
13
+ first .next = top ;
14
+ top = first ;
13
15
}
14
16
15
17
public int pop () {
16
- return 0 ;
18
+ int value = top .val ;
19
+ top = top .next ;
20
+ return value ;
17
21
}
18
22
19
23
public int peek () {
20
- return 0 ;
24
+ return top . val ;
21
25
}
22
26
23
27
public boolean isEmpty () {
24
- return true ;
28
+ return top == null ;
25
29
}
26
30
}
You can’t perform that action at this time.
0 commit comments