aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2023-02-20 04:54:16 +0000
committerterminaldweller <thabogre@gmail.com>2023-02-20 04:54:16 +0000
commit44f9daab4193c250dfe6efe85be6f8d85e6e7d8f (patch)
tree0a2cca6f41285b5d980f10fedae03b4becf67322
parent103 (diff)
downloadleetcode-44f9daab4193c250dfe6efe85be6f8d85e6e7d8f.tar.gz
leetcode-44f9daab4193c250dfe6efe85be6f8d85e6e7d8f.zip
35
-rwxr-xr-x35/main.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/35/main.py b/35/main.py
new file mode 100755
index 0000000..b78265d
--- /dev/null
+++ b/35/main.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+from typing import List
+
+
+class Solution:
+ def searchInsert(self, nums: List[int], target: int) -> int:
+ begin = 0
+ end = len(nums) - 1
+ mid = 0
+ while begin <= end:
+ mid = (end + begin) // 2
+ if target < nums[mid]:
+ end = mid - 1
+ elif target > nums[mid]:
+ begin = mid + 1
+ else:
+ return mid
+ return begin
+
+
+if __name__ == "__main__":
+ solution = Solution()
+ print(solution.searchInsert([1, 3, 5, 6], 5))
+ print(solution.searchInsert([1, 3, 5, 6], 2))
+ print(solution.searchInsert([1, 3, 5, 6], 7))