Compare commits
No commits in common. "0e827099841927355c753d2e13eba5ec2d461110" and "886879c4d7de638ab747e08b4ff1da946b973a62" have entirely different histories.
0e82709984
...
886879c4d7
@ -1,19 +0,0 @@
|
|||||||
class Solution:
|
|
||||||
def twoSum(self, numbers: list[int], target: int) -> list[int]:
|
|
||||||
for idx, num in enumerate(numbers):
|
|
||||||
finding = target - num
|
|
||||||
left = idx
|
|
||||||
right = len(numbers) - 1
|
|
||||||
while left <= right:
|
|
||||||
mid = (left + right) // 2
|
|
||||||
if numbers[mid] == finding:
|
|
||||||
return [idx + 1, mid + 1]
|
|
||||||
if numbers[mid] > finding:
|
|
||||||
right = mid - 1
|
|
||||||
continue
|
|
||||||
if numbers[mid] < finding:
|
|
||||||
left = mid + 1
|
|
||||||
sol = Solution()
|
|
||||||
print(sol.twoSum([2, 7 ,11, 15], 26))
|
|
||||||
print(sol.twoSum([-1, 9], 8))
|
|
||||||
print(sol.twoSum([2,3,4], 6))
|
|
@ -1,10 +0,0 @@
|
|||||||
class Solution:
|
|
||||||
def removeDuplicates(self, nums: List[int]) -> int:
|
|
||||||
k = {}
|
|
||||||
cnt = 0
|
|
||||||
for num in nums:
|
|
||||||
if num not in k:
|
|
||||||
nums[cnt] = num
|
|
||||||
cnt += 1
|
|
||||||
k[num] = 1
|
|
||||||
return cnt
|
|
Loading…
Reference in New Issue
Block a user