Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds Dasia's Stack & Game Result to Lesson 12 #414

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ public class Lesson12 {
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
*/
public String gameResult(ListNode head) {
return null;
ListNode current = head;
int evenPoints = 0;
int oddPoints = 0;
while (current != null) {
if (current.val > current.next.val) {
evenPoints++;
} else if (current.val < current.next.val) {
oddPoints++;
}
current = current.next.next;
}
if (evenPoints > oddPoints) {
return "Even";
} else if (oddPoints > evenPoints) {
return "Odd";
} else {
return "Tie";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ public Stack() {
}

public void push(int value) {
// Your code here
ListNode first = new ListNode(value);
first.next = top;
top = first;
}

public int pop() {
return 0;
if (isEmpty()) {
return -1;
}
int value = top.val;
top = top.next;
return value;
}

public int peek() {
return 0;
return top.val;
}

public boolean isEmpty() {
return true;
return top == null;
}
}
19 changes: 18 additions & 1 deletion lesson_12/structs_ts/src/lesson12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ export class Lesson12 {
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
*/
public gameResult(head: ListNode | null): string {
return '';
let current: ListNode| null = head;
let evenPoints = 0;
let oddPoints = 0;
while (current !== null && current.next != null) {
if (current.val > current.next.val) {
evenPoints++;
} else if (current.val < current.next.val) {
oddPoints++;
}
current =current.next.next != undefined? current.next.next : null;
}
if (evenPoints > oddPoints) {
return 'Even';
} else if (oddPoints > evenPoints) {
return 'Odd';
} else {
return 'Tie';
}
}
}
Loading