Skip to content

Commit 4b70271

Browse files
committed
Chore: Removes comment codefrom Lesson12.java
1 parent 95ae6d0 commit 4b70271

File tree

1 file changed

+10
-39
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+10
-39
lines changed
Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,31 @@
11
package com.codedifferently.lesson12;
22

33
public class Lesson12 {
4-
5-
// public static Node {
6-
// public int data;
7-
// public Node next;
8-
9-
// public Node(int data) {
10-
// this.data = data;
11-
// }
12-
// }
134
/**
145
* Provide the solution to LeetCode 3062 here:
156
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
167
*/
178
public static String gameResult(ListNode head) {
18-
int[] scoreBoard = {0, 0};
9+
int[] scoreBoard = {0, 0}; //Creates an array that will act as our scoreboard...hence the name
1910

20-
while (head.next != null) {
21-
if (head.val != head.next.val && head.val % 2 == 0) {
22-
if (head.val > head.next.val) {
23-
scoreBoard[head.val % 2] += 1;
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
2416
} else {
25-
scoreBoard[head.next.val % 2] += 1;
17+
scoreBoard[head.next.val % 2] += 1;
2618
}
2719
}
2820
head = head.next; // Moves to the next Node
2921
}
3022

3123
if (scoreBoard[0] == scoreBoard[1]) {
32-
return "Tie";
24+
return "Tie"; //Returns tie if the scoreboard is even
3325
} else if (scoreBoard[0] > scoreBoard[1]) {
34-
return "Even";
26+
return "Even"; //if the Even side [0] is greater than 1 return "Even"
3527
} else {
36-
return "Odd";
28+
return "Odd"; // Else return "Odd"
3729
}
3830
}
3931
}
40-
41-
// public static Node createLinkedList(int[] arr) {
42-
// if (arr.length == 0) return null;
43-
44-
// Node head = new Node(arr[0]); //Creates the first node and names it head
45-
// Node current = head; //Tracks the current head inside the loop
46-
47-
// for(int i = 1; i < arr.length; ++i) { //Starts a for loop that is at the second element
48-
// current.next = new Node(arr[i]); //creates a new node and links it
49-
// current = current.next;
50-
// }
51-
// return head;
52-
53-
// }
54-
55-
// public static void main(String[] args) {
56-
// int[] arr = {2, 5, 4, 7, 20, 5};
57-
58-
// System.out.println(createLinkedList(arr));
59-
// }
60-
// }

0 commit comments

Comments
 (0)