Skip to content
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,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) {
return null;
int oddPoints = 0;
int evenPoints = 0;
ListNode current = head;

while (current != null && current.next != null) {
int evenValue = current.val;
int oddValue = current.next.val;

if (evenValue > oddValue) {
evenPoints++;
} else if (oddValue > evenValue) {
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,29 @@ public Stack() {
}

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

public int pop() {
return 0;
if (isEmpty()) {
throw new IllegalStateException("Stack has no values");
}
int valToPop = top.val;
top = top.next;
return valToPop;
}

public int peek() {
return 0;
if (isEmpty()) {
throw new IllegalStateException("Stack has no values");
}

return top.val;
}

public boolean isEmpty() {
return true;
return top == null;
}
}