Skip to content

Commit

Permalink
Merge pull request #1 from longsizhuo123/main
Browse files Browse the repository at this point in the history
龙龙
  • Loading branch information
longsizhuo authored Apr 4, 2023
2 parents 808ac61 + 62597d8 commit b75a9c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 龙龙代码随想录/27. 移除元素.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import List
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
ind = 0
while ind < len(nums):
if nums[ind] == val:
nums.pop(ind)
else:
ind += 1
return len(nums)
14 changes: 14 additions & 0 deletions 龙龙代码随想录/704. 二分查找.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import List
class Solution:
def search(self, nums: List[int], target: int) -> int:
def recursion(nums, left, right, target):
if left > right:
return -1
mid = left + (left - right) // 2
if nums[mid] == target:
return mid
elif nums[mid] < target:
left = mid + 1
else:
right = mid - 1
return recursion(nums, left, right, target)

0 comments on commit b75a9c3

Please sign in to comment.