class Solution(object):
def kthSmallest(self, root, k):
"""
:type root: TreeNode
:type k: int
:rtype: int
"""
stack = []
while stack or root:
while root:
stack.append(root)
root = root.left
root = stack.pop()
k -= 1
if k == 0:
return root.val
root = root.right
class Solution(object):
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
pre = res = ListNode(0)
pre.next = head
while head and head.next:
if head.val == head.next.val:
while head.next and head.val == head.next.val:
head = head.next
head = head.next
pre.next = head
else:
pre = pre.next
head = head.next
return res.next
def reverseBetween(self, head, m, n):
"""
:type head: ListNode
:type m: int
:type n: int
:rtype: ListNode
"""
if n == m:
return head
count = 1
res = ListNode(None)
res.next = head
pre = res
while count < m:
pre = pre.next
count += 1
newhead,head,tail = None,pre.next,pre.next
for i in range(n-m+1):
head.next,newhead,head=newhead,head,head.next
pre.next,tail.next = newhead,head
return res.next