File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,24 @@ public class Lesson12 {
77 * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
88 */
99 public String gameResult (ListNode head ) {
10- return null ;
10+ int even = 0 ;
11+ int odd = 0 ;
12+
13+ while (head != null ) {
14+ if (head .val > head .next .val ) {
15+ even ++;
16+
17+ } else if (head .val < head .next .val ) {
18+ odd ++;
19+ }
20+ head = head .next .next ;
21+ }
22+ if (even > odd ) {
23+ return "Even" ;
24+ }
25+ if (even < odd ) {
26+ return "Odd" ;
27+ }
28+ return "Tie" ;
1129 }
1230}
Original file line number Diff line number Diff line change @@ -10,17 +10,22 @@ public Stack() {
1010
1111 public void push (int value ) {
1212 // Your code here
13+ ListNode newNode = new ListNode (value );
14+ newNode .next = top ;
15+ top = newNode ;
1316 }
1417
1518 public int pop () {
16- return 0 ;
19+ int result = top .val ;
20+ top = top .next ;
21+ return result ;
1722 }
1823
1924 public int peek () {
20- return 0 ;
25+ return top . val ;
2126 }
2227
2328 public boolean isEmpty () {
24- return true ;
29+ return top == null ;
2530 }
2631}
You can’t perform that action at this time.
0 commit comments