Skip to content

Commit

Permalink
Added longest common prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
puneeter committed Dec 29, 2024
1 parent f87ce3d commit ace2afa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LeetCode/LongestCommonPrefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
maximum_common_length = min(len(x) for x in strs)

common_str = ""
for i in range(maximum_common_length):
if all(x[i] == strs[0][i] for x in strs):
common_str += strs[0][i]
else:
break
return common_str
1 change: 1 addition & 0 deletions LeetCode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| [Integer to Roman](IntegerToRoman.py) | :heavy_check_mark: | `#string` `#math` | Python |
| [Invert Binary Tree](InvertBinaryTree.py) | :heavy_check_mark: | `#tree` | Python |
| [K-th Symbol in Grammar](KthSymbolInGrammar.py) | :heavy_check_mark: | `#recursion` | Python |
| [Longest Common Prefix](LongestCommonPrefix.py) | :heavy_check_mark: | `#trie` `#string` | Python |
| [Longest Substring without repeating characters](LongestSubstrWithoutRepeatingChars.py) | :heavy_check_mark: | `#hash table` `#two pointers` `#string` `#sliding window` | Python |
| [Maximum Depth Of Binary Tree](MaximumDepthOfBinaryTree.py) | :heavy_check_mark: | `#recursion` `#tree` | Python |
| [Maximum Subarray](MaximumSubarray.py) | :heavy_check_mark: | `#kadane` `#array` | Python |
Expand Down

0 comments on commit ace2afa

Please sign in to comment.