Skip to content

Commit

Permalink
Feat: Adds, NileJackson's extra credit for lesson12.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nilejack committed Oct 25, 2024
1 parent 32f5984 commit 3824f05
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lesson_12/structs_ts/src/lesson12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,30 @@ export class Lesson12 {
* Provide the solution to LeetCode 3062 here:
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
*/
public gameResult(head: ListNode | null): string {
return '';
public gameResult(head: ListNode | null): String {

Check failure on line 8 in lesson_12/structs_ts/src/lesson12.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using the primitive `string` as a type name, rather than the upper-cased `String`
if (!head) return "Tie";

Check failure on line 9 in lesson_12/structs_ts/src/lesson12.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote


let current: ListNode | null = head;
const scores: number[] = [0, 0];

while (current && current.next) {
if (current.val !== current.next.val && current.val % 2 == 0) {
if (current.val > current.next.val) {
scores[0]++;
} else {
scores[1]++;
}
}
current = current.next;
}
if(scores[0] > scores[1]) {
return "Even";

Check failure on line 26 in lesson_12/structs_ts/src/lesson12.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
} else if (scores[0] < scores[1]) {
return "Odd";

Check failure on line 28 in lesson_12/structs_ts/src/lesson12.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
} else {
return "Tie";

Check failure on line 30 in lesson_12/structs_ts/src/lesson12.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
}
}
}

0 comments on commit 3824f05

Please sign in to comment.