Skip to content

Commit f884ca6

Browse files
authored
Create winner-of-the-linked-list-game.py
1 parent 9cf716c commit f884ca6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# linked list
5+
class Solution(object):
6+
def gameResult(self, head):
7+
"""
8+
:type head: Optional[ListNode]
9+
:rtype: str
10+
"""
11+
cnt = 0
12+
while head:
13+
cnt += cmp(head.val, head.next.val)
14+
head = head.next.next
15+
return "Tie" if cnt == 0 else "Odd" if cnt < 0 else "Even"

0 commit comments

Comments
 (0)