Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- RecursionError: maximum recursion depth exceeded while calling a Python object
- handleMethodsArgumentNotValid
- WebServer
- Instance
- Stock
- Slack
- stock trading
- mongodb
- pyinstaller
- mime type
- EC2
- AWS
- Creon
- KOSDAQ
- Auto Login
- automated system
- Daishin Securities
- creon login
- request param
- Rest
- API
- ExceptionHandler
- spec
- AESCipher
- Version Control
- python
- Web Crawler
- header
- URI
- The Internet
Archives
- Today
- Total
Change the Better World
Longest Common Prefix 본문
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
Example 1:
Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:
Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.
class Solution(object):
def longestCommonPrefix(self, strs):
result = ""
strs = sorted(strs)
for i in range(len(strs[0])):
s = strs[0][i] #frist alphabet
for j in strs:
flag = False
if s == j[i]:
flag = True
else:
flag = False
if flag == True:
result += s
else:
break
return result
Runtime: 33 ms, faster than 41.26% of Python online submissions for Longest Common Prefix.
Memory Usage: 13.9 MB, less than 12.93% of Python online submissions for Longest Common Prefix.
'Programming > Python' 카테고리의 다른 글
Valid Parentheses (0) | 2022.06.11 |
---|---|
Roman to Integer (0) | 2022.06.07 |
Leetcode - Palindrome Number (0) | 2022.06.04 |
Leetcode - Two Sum (0) | 2022.06.03 |
pyinstaller.exe 실행시, "RecursionError: maximum recursion depth exceeded while calling a Python object" 발생 (0) | 2021.03.14 |
Comments