File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1212| 7 | [ Reverse Integer] ( https://leetcode.com/problems/reverse-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ReverseInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/reverse_integer.py ) |
1313| 9 | [ PalindromeNumber] ( https://leetcode.com/problems/palindrome-number/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/PalindromeNumber.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/palindrome_number.py ) |
1414| 13 | [ Roman To Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RomanToInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/roman_to_integer.py ) |
15- | 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LongestCommonPrefix.java ) |
15+ | 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LongestCommonPrefix.java ) [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/longest_common_prefix.py ) |
1616| 20 | [ ValidParentheses] ( https://leetcode.com/problems/valid-parentheses/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ValidParentheses.java ) |
1717| 21 | [ Merge 2 Sorted Lists] ( https://leetcode.com/problems/merge-two-sorted-lists/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/Merge2SortedLists.java ) |
1818| 26 | [ Remove Duplicates From Sorted Array] ( https://leetcode.com/problems/remove-duplicates-from-sorted-array/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RemoveDuplicatesFromSortedArray.java ) |
Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+
4+ class Solution :
5+ def longestCommonPrefix (self , array : List [str ]) -> str :
6+ if len (array ) == 0 :
7+ return ''
8+
9+ result = array [0 ]
10+ for index in range (1 , len (array )):
11+ result = self .longestCommonPrefix2Strings (result , array [index ])
12+ return result
13+
14+ def longestCommonPrefix2Strings (self , first : str , second : str ) -> str :
15+ for index in range (min (len (first ), len (second ))):
16+ if first [index ] != second [index ]:
17+ return first [0 :index ]
18+
19+ return first if len (first ) < len (second ) else second
You can’t perform that action at this time.
0 commit comments