-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongestCommonPrefixWIP
More file actions
31 lines (24 loc) · 996 Bytes
/
longestCommonPrefixWIP
File metadata and controls
31 lines (24 loc) · 996 Bytes
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
#attempted a solution besides the one I resolved with guidance but I failed. Cannot seem to get the startswith method to work in the while loop. In other words, I tried to compare every character in one string to the other
#but I could not isolate the one with prefix. maybe later
class Solution:
def longestCommonPrefix(self, myArr):
prefix = myArr[0]
print(prefix)
myResult = ""
nn = len(prefix)
if myArr == "":
return
#str1 = myArr[0]
str2 = myArr[1]
str3 = myArr[2]
for i in str2[0:]:
print(i)
while i.startswith(nn(i)):
print(prefix[:1])
print(i.startswith(prefix[:1]))
myResult += i
#prefix = prefix[:1]
nn += 1
return prefix
myVar = Solution()
myVar.longestCommonPrefix(["flower","flow","flight"])