Skip to content

Commit d598b70

Browse files
author
AmiyahJo
committed
feat: adds while loop using my current pointer
1 parent e566771 commit d598b70

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lesson_12/structs_ts/src/lesson12.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ export class Lesson12 {
77
*/
88
public gameResult(head: ListNode | null): string {
99
let [oddPoints, evenPoints] = [0,0];
10-
1110
let current = head;
1211

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-
// }
12+
while (current != null && current.next != null) {
13+
if (current.val > current.next.val) {
14+
evenPoints++;
15+
} else if (current.val < current.next.val) {
16+
oddPoints++;
17+
}
18+
current = current.next ? current.next.next || null : null;
19+
}
2120

2221
if (oddPoints > evenPoints) {
2322
return "Odd";

0 commit comments

Comments
 (0)