Skip to content

Commit

Permalink
feat: added Zion's GameResult and Stack Results to lesson_12 hw
Browse files Browse the repository at this point in the history
  • Loading branch information
zionbuch committed Oct 23, 2024
1 parent 8d6467e commit cc3510f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ 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) {
ListNode current = head;
int even = 0;
int odd = 0;
while (current.next != null) {
ListNode nextNode = current.next;
if (current.val < nextNode.val) {
odd++;
}
if (current.val > nextNode.val) {
even++;
}
current = nextNode.next;
}
if (even > odd) {
return "Even";
}
if (even < odd) {
return "Odd";
}

if (even == odd) {
return "Tie";
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ public Stack() {
}

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

public int pop() {
return 0;
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;
}
}

0 comments on commit cc3510f

Please sign in to comment.