Skip to content

Commit

Permalink
--
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirPaulb committed Apr 5, 2022
1 parent e3348d1 commit 12bc315
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 11_Binary-Search/06. Valid Triangle Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://leetcode.com/problems/valid-triangle-number/
# https://youtu.be/PqEiJDdt3S4

class Solution:
def triangleNumber(self, nums: List[int]) -> int:
nums.sort()
res = 0

for i in range(len(nums)-1, 1, -1):
r = i - 1
l = 0
while l < r:
if nums[l] + nums[r] > nums[i]:
res += (r - l)
r -= 1
else:
l += 1

return res

# Time: O(N^2)
# Space: O(1)
13 changes: 13 additions & 0 deletions 16_String/03. Longest Common Prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://leetcode.com/problems/longest-common-prefix/
# https://youtu.be/0sWShKIJoo4

class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
res = ""
for i in range(len(strs[0])):
for st in strs:
if i == len(st) or strs[0][i] != st[i]:
return res
res += strs[0][i]

return res

0 comments on commit 12bc315

Please sign in to comment.