yan chuanli 2 years ago
parent
commit
6d905de3c0
2 changed files with 36 additions and 4 deletions
  1. 4 4
      bracket_match.py
  2. 32 0
      remove_array_duplicates.py

+ 4 - 4
is_valid.py → bracket_match.py

@@ -33,10 +33,10 @@ def isValid(s: str):
 @pytest.mark.parametrize(
     "s, expect",
     [
-        # ("()[]", True),
-        # ("(({[])}", False),
-        # ("(]", False),
-        # ("([{}])", True),
+        ("()[]", True),
+        ("(({[])}", False),
+        ("(]", False),
+        ("([{}])", True),
         ("21[o{00}j]", False)
     ]
 )

+ 32 - 0
remove_array_duplicates.py

@@ -0,0 +1,32 @@
+from typing import List
+
+
+def removeDuplicates(nums: List[int]):
+    # 暴力解法
+    lens = len(nums)
+    # i = 0
+    # while i < lens-1:
+    #     if nums[i] == nums[i + 1]:
+    #         nums.remove(nums[i])
+    #         lens -= 1
+    #         while i != 0:
+    #             i -= 1
+    #     else:
+    #         i += 1
+    # return len(nums)
+
+    # 快慢指针法
+    if not nums:
+        return 0
+
+    slow = 1
+    for fast in range(1,lens):
+        if nums[fast] != nums[fast - 1]:
+            nums[slow] = nums[fast]
+            slow += 1
+    return slow
+
+
+print(removeDuplicates([0, 0, 1, 1, 2, 3, 3]))
+
+