Skip to content

Commit 7dbb709

Browse files
authored
Create Day-27_Longest_Uncommon_Subsequence.py
1 parent 1cfa73a commit 7dbb709

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#######################
2+
1. Sort the words in order of decreasing length of strings and count the number of each word in a hashmap and do
3+
#######################
4+
5+
6+
class Solution(object):
7+
def findLUSlength(self, strs):
8+
def isSub(w1, w2, count):
9+
for i in w2:
10+
if i == w1[count]:
11+
count += 1
12+
if count == len(w1):
13+
return True
14+
return count == len(w2)
15+
16+
d = collections.Counter(strs)
17+
strs.sort(key = len, reverse = True)
18+
for i in range(len(strs)):
19+
if d[strs[i]] == 1:
20+
res = any(isSub(strs[i], strs[j], 0) for j in range(i))
21+
if res == False: return len(strs[i])
22+
return -1

0 commit comments

Comments
 (0)