Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c8237c6

Browse filesBrowse files
authored
Create 27_findLUSlength.py
1 parent 727e640 commit c8237c6
Copy full SHA for c8237c6

File tree

Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def findLUSlength(self, words):
3+
def isSubsequence(s, t):
4+
t = iter(t)
5+
return all(c in t for c in s)
6+
7+
words.sort(key = lambda x:-len(x))
8+
for i, word in enumerate(words):
9+
if all(not isSubsequence(word, words[j]) for j in range(len(words)) if j != i):
10+
return len(word)
11+
12+
return -1

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.