Skip to content

Commit 4c8b8d4

Browse files
author
Dominik Schauer
committed
added solutions for 217; updated Readme; improved coding style for 167
1 parent fc731e7 commit 4c8b8d4

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
Here I brag about how accomplished and productive I am by dumping my working LeetCode solutions. Since no one can see the failed attempts I look supersmart. Nevermind my profile.
1+
Here I brag about how accomplished and productive I am by dumping my working LeetCode solutions. Since no one can see the failed attempts I look supersmart to potential employers.
22

3+
My profile:
34
https://leetcode.com/user6659P/
5+
6+
Helpful guideline for starting with LeetCode:
7+
https://seanprashad.com/leetcode-patterns/

algorithms/15_3Sum.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def threeSum(self, nums: List[int]) -> List[List[int]]:
3+

algorithms/167_two_sum_ii_input_array_is_sorted.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def twoSum(self, numbers: List[int], target: int) -> List[int]:
2020
while True:
2121
current_sum = numbers[left] + numbers[right]
2222
if(current_sum == target):
23-
return((left+1, right+1));
23+
return((left+1, right+1))
2424
elif(current_sum < target):
25-
left += 1;
25+
left += 1
2626
else:
27-
right -= 1;
27+
right -= 1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# By using a dictionary to remember each value we had seen before,
2+
# we will know in case we encounter the same value a second time (i.e. it's a duplciate)
3+
# Obviously there's no need to go this far if there aren't at least two
4+
# values in the array, since then it's impossible to have duplicates.
5+
6+
class Solution:
7+
def containsDuplicate(self, nums: List[int]) -> bool:
8+
if(len(nums) < 2):
9+
return False
10+
11+
value_dict = {}
12+
13+
for i in range(0,len(nums)):
14+
if(nums[i] in value_dict):
15+
return True
16+
else:
17+
value_dict[nums[i]] = None
18+
19+
return False
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# By sorting the array we can subsequently check if two adjacent numbers
2+
# in it have the same value (i.e. if they are duplicates)
3+
# Obviously there's no need to go this far if there aren't at least two
4+
# values in the array, since then it's impossible to have duplicates.
5+
6+
class Solution:
7+
def containsDuplicate(self, nums: List[int]) -> bool:
8+
if(len(nums) < 2):
9+
return False
10+
else:
11+
nums.sort()
12+
13+
for i in range(0,len(nums)-1):
14+
if(nums[i] == nums[i+1]):
15+
return True
16+
17+
return False

0 commit comments

Comments
 (0)