Skip to content

Commit 7246cf7

Browse files
committed
Add line break and remove unnecessary string conversion
1 parent 23c97c0 commit 7246cf7

File tree

5 files changed

+36
-40
lines changed

5 files changed

+36
-40
lines changed

best-time-to-buy-and-sell-stock/bhyun-kim.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,27 @@
1414

1515
from typing import List
1616

17+
1718
class Solution:
1819
def maxProfit(self, prices: List[int]) -> int:
1920
profit = 0
2021
prev_max = 0
2122

22-
for i in reversed(range(len(prices)-1)):
23-
prev_max = max(prev_max, prices[i+1])
24-
profit = max(profit, prev_max-prices[i])
23+
for i in reversed(range(len(prices) - 1)):
24+
prev_max = max(prev_max, prices[i + 1])
25+
profit = max(profit, prev_max - prices[i])
2526

2627
return profit
27-
2828

2929

3030
def main():
31-
test_cases = [
32-
[[7,1,5,3,6,4], 5],
33-
[[7,6,4,3,1], 0]
34-
]
31+
test_cases = [[[7, 1, 5, 3, 6, 4], 5], [[7, 6, 4, 3, 1], 0]]
3532
s = Solution()
36-
33+
3734
for test_case in test_cases:
3835
prices_input, expected = test_case
3936
assert s.maxProfit(prices_input) == expected
4037

41-
if __name__ == '__main__':
38+
39+
if __name__ == "__main__":
4240
main()
43-

contains-duplicate/bhyun-kim.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@
1313

1414
from typing import List
1515

16+
1617
class Solution:
1718
def containsDuplicate(self, nums: List[int]) -> bool:
1819
return len(set(nums)) != len(nums)
1920

21+
2022
def main():
2123
test_cases = [
22-
[[1,2,3,1], True,]
23-
[[1,2,3,4], False],
24-
[[1,1,1,3,3,4,3,2,4,2], True]
24+
[
25+
[1, 2, 3, 1],
26+
True,
27+
][[1, 2, 3, 4], False],
28+
[[1, 1, 1, 3, 3, 4, 3, 2, 4, 2], True],
2529
]
2630
s = Solution()
27-
31+
2832
for test_case in test_cases:
2933
nums_input, expected = test_case
3034
assert s.containsDuplicate(nums_input) == expected
3135

32-
if __name__ == '__main__':
36+
37+
if __name__ == "__main__":
3338
main()
34-

two-sum/bhyun-kim.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
from typing import List
1515

16+
1617
class Solution:
1718
def twoSum(self, nums: List[int], target: int) -> List[int]:
18-
1919
hashmap = {}
2020

2121
for i in range(len(nums)):
@@ -25,18 +25,15 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
2525

2626
hashmap[nums[i]] = i
2727

28+
2829
def main():
29-
test_cases = [
30-
[2,7,11,15], 9, [0,1],
31-
[3,2,4], 6, [1,2],
32-
[3,3], 6, [0,1]
33-
]
30+
test_cases = [[2, 7, 11, 15], 9, [0, 1], [3, 2, 4], 6, [1, 2], [3, 3], 6, [0, 1]]
3431
s = Solution()
35-
32+
3633
for test_case in test_cases:
3734
nums_input, target_input, expected = test_case
3835
assert sorted(s.twoSum(nums_input, target_input)) == expected
3936

40-
if __name__ == '__main__':
37+
38+
if __name__ == "__main__":
4139
main()
42-

valid-anagram/bhyun-kim.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,23 @@
99
Space complexity: O(1)
1010
"""
1111

12+
1213
class Solution:
1314
def isAnagram(self, s: str, t: str) -> bool:
14-
1515
if sorted(s) == sorted(t):
1616
return True
1717
else:
1818
return False
1919

2020

2121
def main():
22-
test_cases = [
23-
["anagram", "nagaram", True],
24-
["rat", "car", False]
25-
]
22+
test_cases = [["anagram", "nagaram", True], ["rat", "car", False]]
2623
s = Solution()
27-
24+
2825
for test_case in test_cases:
2926
s_input, t_input, expected = test_case
3027
assert s.isAnagram(s_input, t_input) == expected
3128

32-
if __name__ == '__main__':
29+
30+
if __name__ == "__main__":
3331
main()
34-

valid-palindrome/bhyun-kim.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@
1414
class Solution:
1515
def isPalindrome(self, s: str) -> bool:
1616
s = s.lower()
17-
s = list([c for c in s
18-
if c.isalpha() or c.isnumeric()])
19-
s = "".join(s)
17+
s = [c for c in s if c.isalpha() or c.isnumeric()]
2018
return s == s[::-1]
2119

20+
2221
def main():
2322
test_cases = [
2423
["A man, a plan, a canal: Panama", True],
2524
["race a car", False],
26-
[" ", True]
25+
[" ", True],
2726
]
2827
s = Solution()
29-
28+
3029
for test_case in test_cases:
3130
s_input, expected = test_case
3231
assert s.isPalindrome(s_input) == expected
3332

34-
if __name__ == '__main__':
33+
34+
if __name__ == "__main__":
3535
main()
36+

0 commit comments

Comments
 (0)