Skip to content

Commit 49d841f

Browse files
committed
Nia_P refactor: improve formatting and readability of gameResult method
1 parent 7450dd4 commit 49d841f

File tree

1 file changed

+27
-25
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+27
-25
lines changed

lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@ 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-
if (head == null || head.next == null) {
11-
return "No Pairs";
12-
}
13-
14-
int oddPoints = 0, evenPoints = 0;
15-
ListNode current = head;
16-
17-
while (current != null && current.next != null) {
18-
if (current.val < current.next.val) {
19-
oddPoints++;
20-
} else {
21-
evenPoints++;
22-
}
23-
current = current.next.next;
24-
}
25-
26-
27-
if (oddPoints > evenPoints) {
28-
return "Odd";
29-
} else if (evenPoints > oddPoints) {
30-
return "Even";
31-
} else {
32-
return "Tie";
33-
}
10+
if (head == null || head.next == null) {
11+
return "No Pairs";
3412
}
3513

36-
}
14+
int oddPoints = 0, evenPoints = 0;
15+
ListNode current = head;
16+
17+
while (current != null && current.next != null) {
18+
19+
if (current.val < current.next.val) {
20+
21+
oddPoints++;
22+
23+
} else {
24+
25+
evenPoints++;
26+
}
27+
current = current.next.next;
28+
}
29+
30+
if (oddPoints > evenPoints) {
31+
return "Odd";
32+
} else if (evenPoints > oddPoints) {
33+
return "Even";
34+
} else {
35+
return "Tie";
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)