-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRing Out.py
More file actions
29 lines (26 loc) · 732 Bytes
/
Ring Out.py
File metadata and controls
29 lines (26 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class ListNode:
def __init__(self, x):
self.val = x
self.prev = None
self.next = None
class Solution:
def ringOut(self, n):
head = ListNode(1)
current = head
for i in xrange(2, n + 1):
item = ListNode(i)
item.prev = current
current.next = item
current = current.next
head.prev = current
current.next = head
current = head
count = n
while count > 1:
current.prev.next = current.next
current.next.prev = current.prev
current = current.next.next
count = count - 1
return current.val
result = Solution()
print result.ringOut(100000)