File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -7,17 +7,23 @@ 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- ListNode current = head ;
11- int evenPoints = 0 ;
12- int oddPoints = 0 ;
13- while (current .next != null ){
14- if (current .val > current .next .val );
15- evenPoints ++
16- else if (current .val <current .next .val );
17- oddPoints ++
18- else
19-
10+ ListNode current = head ;
11+ int evenPoints = 0 ;
12+ int oddPoints = 0 ;
13+ while (current != null && current .next != null ) {
14+ if (current .val > current .next .val ) {
15+ evenPoints ++;
16+ } else if (current .val < current .next .val ) {
17+ oddPoints ++;
18+ }
19+ current = current .next .next ;
20+ }
21+ if (evenPoints > oddPoints ) {
22+ return "Even" ;
23+ } else if (oddPoints > evenPoints ) {
24+ return "Odd" ;
25+ } else {
26+ return "Tie" ;
2027 }
21- return null ;
2228 }
2329}
You can’t perform that action at this time.
0 commit comments