-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from longsizhuo123/main
龙龙
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |