Skip to content

Commit b4bab2d

Browse files
feat: adds Karens lesson_12
1 parent ac458a6 commit b4bab2d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

code-differently-25-q1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 7b3bd25441ace95f23357f28344eec7110953645

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ 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-
return null;
10+
11+
//team values
12+
int oddValue = 0;
13+
int evenValue = 0;
14+
15+
//iterate through listNode
16+
//grabbed items
17+
//accessed value
18+
19+
while (head != null && head.next != null) {
20+
int val1 = head.val; //at head node, accessing value. head val is even
21+
int val2 = head.next.val; // at next node, accessing value. next val is odd
22+
23+
//compare values
24+
if (val1 > val2) {
25+
evenValue += 1;
26+
} else if (val1 < val2) {
27+
oddValue += 1;
28+
}
29+
// go to next value
30+
31+
}
32+
33+
34+
35+
36+
37+
38+
39+
// loop through lstNode
40+
41+
// grab lstNode values
42+
//compare them
43+
//return even or odd depending on which value is higher
44+
45+
46+
47+
1148
}
49+
1250
}

0 commit comments

Comments
 (0)