@@ -1,14 +1,26 @@
-def climbStairs(n: int) -> int:
- if n < 1 or n > 45:
- return 0
- else:
- a = 1
- b = 1
- for i in range(2, n + 1):
- a, b = b, a + b
- return b
-
-print(climbStairs(4))
+# def climbStairs(n: int) -> int:
+# if n < 1 or n > 45:
+# return 0
+# else:
+# a = 1
+# b = 1
+# for i in range(2, n + 1):
+# a, b = b, a + b
+# return b
+
+# print(climbStairs(4))
+def f(n):
+ cach = {}
+ def g(n):
+ if n == 1:
+ return 1
+ if n == 2:
+ return 2
+ else:
+ if g(n - 1) in cach[n - 1]:
+ return cach[n - 1] + g(n)
@@ -1,4 +1,14 @@
+from typing import Optional
+from utils import ListNode, list_to_linklist
-num = [1,2,1,4,5]
-print(list(set(num)))
+def deleteDuplicates(head: Optional[ListNode]) -> Optional[ListNode]:
+ lens = 0
+ p = head
+ while p:
+ lens += 1
+ p = p.next
+ return lens
+print(deleteDuplicates(list_to_linklist([1, 2, 3, 6, 8])))
@@ -0,0 +1,21 @@
+ if not head:
+ return head
+ while p.next:
+ if p.val == p.next.val:
+ p.next = p.next.next
+print(deleteDuplicates(list_to_linklist([1, 1, 2])))
@@ -35,4 +35,20 @@ def list_to_linklist(arr):
p = p.next
return head
+# 计算链表长度
+def len_of_linklist(head):
+def deleteNode(node):
+ node.val = node.next.val
+ node.next = node.next.next