-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3062.java
28 lines (26 loc) · 885 Bytes
/
_3062.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions.fourththousand;
import com.fishercoder.common.classes.ListNode;
public class _3062 {
public static class Solution1 {
public String gameResult(ListNode head) {
int oddPoints = 0;
int evenPoints = 0;
ListNode even = head;
ListNode odd = head.next;
while (odd != null && even != null) {
if (even.val > odd.val) {
evenPoints++;
} else {
oddPoints++;
}
if (even.next != null && odd.next != null) {
even = even.next.next;
odd = odd.next.next;
} else {
break;
}
}
return evenPoints > oddPoints ? "Even" : evenPoints == oddPoints ? "Tie" : "Odd";
}
}
}