File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,26 @@ 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 oddValue = 0 ;
11+ int evenValue = 0 ;
12+
13+ while (head != null && head .next != null ) {
14+ int val1 = head .val ;
15+ int val2 = head .next .val ;
16+
17+ if (val1 < val2 ) {
18+ oddValue += val1 ;
19+ } else if (val2 < val1 ) {
20+ evenValue += 1 ;
21+ }
22+ head = head .next .next ;
23+ }
24+ if (oddValue > evenValue ) {
25+ return "Odd" ;
26+ } else if (evenValue > oddValue ) {
27+ return "Even" ;
28+ } else {
29+ return "Tie" ;
30+ }
1131 }
1232}
Original file line number Diff line number Diff line change @@ -9,18 +9,22 @@ public Stack() {
99 }
1010
1111 public void push (int value ) {
12- // Your code here
12+ ListNode newNode = new ListNode (value );
13+ newNode .next = top ;
14+ top = newNode ;
1315 }
1416
1517 public int pop () {
16- return 0 ;
18+ int value = top .val ;
19+ top = top .next ;
20+ return value ;
1721 }
1822
1923 public int peek () {
20- return 0 ;
24+ return top . val ;
2125 }
2226
2327 public boolean isEmpty () {
24- return true ;
28+ return top == null ;
2529 }
2630}
You can’t perform that action at this time.
0 commit comments