Skip to content

Commit 946a92f

Browse files
committed
fix: improve code formatting and comments in Lesson12.java and Stack.java
1 parent 4e0b057 commit 946a92f

File tree

1 file changed

+13
-9
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+13
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@ public class Lesson12 {
66
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
77
*/
88
public static String gameResult(ListNode head) {
9-
int[] scoreBoard = {0, 0}; //Creates an array that will act as our scoreboard...hence the name
9+
int[] scoreBoard = {0, 0}; // Creates an array that will act as our scoreboard...hence the name
1010

11-
while (head.next != null) { //Creates a loop that runs until the head Linked list is empty || null
12-
if (head.val != head.next.val && head.val % 2 == 0) { //Checks if the current node's value is not equal to the node next to it.
13-
//Also will check if the current not's value is even ( % 2 dividing by 2 to detemine)
14-
if (head.val > head.next.val) {//Updates the array based on index.
15-
scoreBoard[head.val % 2] += 1; //If the head is divisible by 2 then update the first Even teams point
11+
while (head.next
12+
!= null) { // Creates a loop that runs until the head Linked list is empty || null
13+
if (head.val != head.next.val
14+
&& head.val % 2
15+
== 0) { // Checks if the current node's value is not equal to the node next to it.
16+
// Also will check if the current not's value is even ( % 2 dividing by 2 to detemine)
17+
if (head.val > head.next.val) { // Updates the array based on index.
18+
scoreBoard[head.val % 2] +=
19+
1; // If the head is divisible by 2 then update the first Even teams point
1620
} else {
17-
scoreBoard[head.next.val % 2] += 1;
21+
scoreBoard[head.next.val % 2] += 1;
1822
}
1923
}
2024
head = head.next; // Moves to the next Node
2125
}
2226

2327
if (scoreBoard[0] == scoreBoard[1]) {
24-
return "Tie"; //Returns tie if the scoreboard is even
28+
return "Tie"; // Returns tie if the scoreboard is even
2529
} else if (scoreBoard[0] > scoreBoard[1]) {
26-
return "Even"; //if the Even side [0] is greater than 1 return "Even"
30+
return "Even"; // if the Even side [0] is greater than 1 return "Even"
2731
} else {
2832
return "Odd"; // Else return "Odd"
2933
}

0 commit comments

Comments
 (0)