post_href
stringlengths
57
213
python_solutions
stringlengths
71
22.3k
slug
stringlengths
3
77
post_title
stringlengths
1
100
user
stringlengths
3
29
upvotes
int64
-20
1.2k
views
int64
0
60.9k
problem_title
stringlengths
3
77
number
int64
1
2.48k
acceptance
float64
0.14
0.91
difficulty
stringclasses
3 values
__index_level_0__
int64
0
34k
https://leetcode.com/problems/find-the-difference/discuss/1969523/Python3-runtime%3A-48ms-52.48-memory%3A-13.9mb-33.89
class Solution: def findTheDifference(self, string: str, target: str) -> str: if not string and not target: return True if not string: return target if not target: return False visited = [0] * 26 for i in range(len(string)): idx = ord(string[i]) - ord('a') visited[idx] += 1 for i in range(len(target)): idx = ord(target[i]) - ord('a') if visited[idx] == 0: return target[i] visited[idx] -= 1 return True
find-the-difference
Python3 runtime: 48ms 52.48% memory: 13.9mb 33.89%
arshergon
1
47
find the difference
389
0.603
Easy
6,700
https://leetcode.com/problems/find-the-difference/discuss/1920036/Easy-simple-python-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: d= defaultdict(int) for i in s: d[i]+=1 for j in t: d[j]+=1 for key in d: if d[key] %2==1: return key
find-the-difference
Easy simple python solution
Buyanjargal
1
84
find the difference
389
0.603
Easy
6,701
https://leetcode.com/problems/find-the-difference/discuss/1911593/Simple-Dictionary-oror-No-XOR-oror-No-Sorting-oror-Full-Explanation-with-Example
class Solution: def findTheDifference(self, s: str, t: str) -> str: d = Counter(t) #stores the frequency of t for i in s: d[i] -= 1 #every time we decrement the frequency of dictionary which stores the frequency of t if d[i] == 0: del d[i] #if the frequency becomes zero delete that key from dictionary a = str(d.keys()) #print(a) --->"dict_keys(['e'])" return a[12]
find-the-difference
✅Simple Dictionary || No XOR || No Sorting || Full Explanation with Example
Dev_Kesarwani
1
57
find the difference
389
0.603
Easy
6,702
https://leetcode.com/problems/find-the-difference/discuss/1752397/Python-Curated-List-of-cool-oneliners
class Solution: def findTheDifference(self, s: str, t: str) -> str: return chr(reduce(xor, map(ord, chain(s, t))))
find-the-difference
[Python] Curated List of cool oneliners
sidheshwar_s
1
39
find the difference
389
0.603
Easy
6,703
https://leetcode.com/problems/find-the-difference/discuss/1752397/Python-Curated-List-of-cool-oneliners
class Solution: def findTheDifference(self, s: str, t: str) -> str: return chr(reduce(lambda x, y: x ^ y, map(ord, s + t)))
find-the-difference
[Python] Curated List of cool oneliners
sidheshwar_s
1
39
find the difference
389
0.603
Easy
6,704
https://leetcode.com/problems/find-the-difference/discuss/1752397/Python-Curated-List-of-cool-oneliners
class Solution: def findTheDifference(self, s: str, t: str) -> str: return list(Counter(t) - Counter(s))[0]
find-the-difference
[Python] Curated List of cool oneliners
sidheshwar_s
1
39
find the difference
389
0.603
Easy
6,705
https://leetcode.com/problems/find-the-difference/discuss/1752397/Python-Curated-List-of-cool-oneliners
class Solution: def findTheDifference(self, s: str, t: str) -> str: return next(iter(Counter(t) - Counter(s)))
find-the-difference
[Python] Curated List of cool oneliners
sidheshwar_s
1
39
find the difference
389
0.603
Easy
6,706
https://leetcode.com/problems/find-the-difference/discuss/1752397/Python-Curated-List-of-cool-oneliners
class Solution: def findTheDifference(self, s: str, t: str) -> str: return "".join(Counter(t) - Counter(s))
find-the-difference
[Python] Curated List of cool oneliners
sidheshwar_s
1
39
find the difference
389
0.603
Easy
6,707
https://leetcode.com/problems/find-the-difference/discuss/1751858/Python-Easy-1-line-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: return chr(sum([ord(c) for c in t]) - sum([ord(c) for c in s]))
find-the-difference
[Python] Easy 1 line solution
nomofika
1
155
find the difference
389
0.603
Easy
6,708
https://leetcode.com/problems/find-the-difference/discuss/1751694/Python-oror-Easy-Solution-oror-96-Faster-and-96-Space-Efficient
class Solution: def findTheDifference(self, s: str, t: str) -> str: for i in set(t): if s.count(i) != t.count(i): return i
find-the-difference
Python || Easy Solution || 96% Faster and 96% Space Efficient
cherrysri1997
1
19
find the difference
389
0.603
Easy
6,709
https://leetcode.com/problems/find-the-difference/discuss/1751193/python-easy-to-understand
class Solution: def findTheDifference(self, s: str, t: str) -> str: a = [] for i in range(len(t)): a.append(t[i]) for i in range(len(s)): a.remove(s[i]) ans = a[0] return ans
find-the-difference
python easy to understand
ggeeoorrggee
1
25
find the difference
389
0.603
Easy
6,710
https://leetcode.com/problems/find-the-difference/discuss/1591194/Python-faster-than-87.94
class Solution(object): def findTheDifference(self, s, t): """ :type s: str :type t: str :rtype: str """ for c in t: if s.count(c) != t.count(c): return c
find-the-difference
Python faster than 87.94%
ckayfok
1
92
find the difference
389
0.603
Easy
6,711
https://leetcode.com/problems/find-the-difference/discuss/1260511/Python3-dollarolution-(95-Faster)
class Solution: def findTheDifference(self, s: str, t: str) -> str: s = Counter(s) t = Counter(t) for i in (t-s): return i
find-the-difference
Python3 $olution (95% Faster)
AakRay
1
316
find the difference
389
0.603
Easy
6,712
https://leetcode.com/problems/find-the-difference/discuss/1062566/Python-very-simple-solution-with-Counter
class Solution: def findTheDifference(self, s: str, t: str) -> str: diff = Counter(t) - Counter(s) return list(diff.keys())[0]
find-the-difference
Python - very simple solution with Counter
angelique_
1
71
find the difference
389
0.603
Easy
6,713
https://leetcode.com/problems/find-the-difference/discuss/249886/Solution-using-Counter
class Solution: def findTheDifference(self, s: str, t: str) -> str: from collections import Counter s_counter = Counter(s) t_counter = Counter(t) return list(t_counter - s_counter)[0]
find-the-difference
Solution using Counter
compbuzz09
1
73
find the difference
389
0.603
Easy
6,714
https://leetcode.com/problems/find-the-difference/discuss/2848549/python3
class Solution: def findTheDifference(self, s: str, t: str) -> str: # for each unique char in t for c in set(t): # if # of char in t > # of char in s, it was added to t if t.count(c) > s.count(c): return c
find-the-difference
python3
wduf
0
1
find the difference
389
0.603
Easy
6,715
https://leetcode.com/problems/find-the-difference/discuss/2846864/Easist-Solution-in-Python
class Solution: def findTheDifference(self, s: str, t: str) -> str: set_t = set(t) for char in set_t: if t.count(char) != s.count(char): return char
find-the-difference
Easist Solution in Python
namashin
0
1
find the difference
389
0.603
Easy
6,716
https://leetcode.com/problems/find-the-difference/discuss/2846432/bit-manip-python3-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: res = 0 for i in s+t: res^=ord(i) return chr(res)
find-the-difference
bit manip python3 solution
Cosmodude
0
1
find the difference
389
0.603
Easy
6,717
https://leetcode.com/problems/find-the-difference/discuss/2834982/Python-simple-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: list1 = [x for x in t] list2 = [x for x in s] list1.sort() list2.sort() list2.append(0) print(list1) print(list2) reslist = [list1[i] for i in range(len(list1)) if list1[i] != list2[i] ] res = ''.join(reslist) print (res) return reslist[0]
find-the-difference
Python simple solution
user1079z
0
3
find the difference
389
0.603
Easy
6,718
https://leetcode.com/problems/find-the-difference/discuss/2834528/Python-solution-oror-O(n)-time-oror-O(n)-space
class Solution: def findTheDifference(self, s: str, t: str) -> str: d = {} for i in s: try: d[i] += 1 except: d[i] = 1 for i in t: try: d[i] -= 1 if d[i] < 0: return i except: return i
find-the-difference
Python solution || O(n) time || O(n) space
Pavel_Kos
0
2
find the difference
389
0.603
Easy
6,719
https://leetcode.com/problems/find-the-difference/discuss/2832365/dictionary-solution-python
class Solution: def findTheDifference(self, s: str, t: str) -> str: dict1={} dict2 = {} for x in s: if x not in dict1: dict1[x]=1 else: dict1[x]=dict1[x]+1 for x in t: if x not in dict2: dict2[x]=1 else: dict2[x]=dict2[x]+1 print(dict1) print(dict2) for x in dict2: if x not in dict1: return x else: if dict2[x]!=dict1[x]: return x
find-the-difference
dictionary solution python
sahityasetu1996
0
3
find the difference
389
0.603
Easy
6,720
https://leetcode.com/problems/find-the-difference/discuss/2831104/Better-one-line-python-solution-O(n)
class Solution: def findTheDifference(self, s: str, t: str) -> str: return chr(sum([ord(l) for l in t]) - sum([ord(l) for l in s]))
find-the-difference
Better one line python solution O(n)
lornedot
0
1
find the difference
389
0.603
Easy
6,721
https://leetcode.com/problems/find-the-difference/discuss/2831092/One-line-python-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: return chr(abs(sum([ord(l) for l in s]) + sum([-1* ord(l) for l in t])))
find-the-difference
One line python solution
lornedot
0
2
find the difference
389
0.603
Easy
6,722
https://leetcode.com/problems/find-the-difference/discuss/2829324/Easy-python-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: for i in set(t): if s.count(i) != t.count(i): return i
find-the-difference
Easy python solution
_debanjan_10
0
1
find the difference
389
0.603
Easy
6,723
https://leetcode.com/problems/find-the-difference/discuss/2826203/Easy-Python-Solution-Using-HashMap-or-dict
class Solution: def findTheDifference(self, s: str, t: str) -> str: final_word = s + t hashMap = {} for i in final_word: hashMap[i] = final_word.count(i) print(hashMap) for i in hashMap: if hashMap[i] % 2 != 0: return i
find-the-difference
Easy Python Solution - Using HashMap or dict
danishs
0
3
find the difference
389
0.603
Easy
6,724
https://leetcode.com/problems/find-the-difference/discuss/2820287/simple-python-using-dictionary-beats-75
class Solution: def findTheDifference(self, s: str, t: str) -> str: string = "abcdefghijklmnopqrstuvwxyz" hashmap = {string[k]:0 for k in range(len(string))} for i in range(len(s)): hashmap[s[i]]+=1 for i in range(len(t)): hashmap[t[i]]+=1 for k,v in hashmap.items(): if v%2: return k
find-the-difference
simple python using dictionary beats 75%
sudharsan1000m
0
3
find the difference
389
0.603
Easy
6,725
https://leetcode.com/problems/find-the-difference/discuss/2795178/Python-Solution-(With-basics-concepts)
class Solution: def findTheDifference(self, s: str, t: str) -> str: s1 = [] t1 = [] alpha = string.ascii_lowercase for i in alpha: s1.append(s.count(i)) t1.append(t.count(i)) for i in range(0,26): if (s1[i]-t1[i])!=0: return alpha[i]
find-the-difference
Python Solution (With basics concepts)
VINAY_KUMAR_V_C
0
3
find the difference
389
0.603
Easy
6,726
https://leetcode.com/problems/find-the-difference/discuss/2788536/Simple-Python3-Solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: if s == t: return "" for i in t: if s.count(i) != t.count(i): return i
find-the-difference
Simple Python3 Solution
vivekrajyaguru
0
4
find the difference
389
0.603
Easy
6,727
https://leetcode.com/problems/find-the-difference/discuss/2778442/python-one-line
class Solution: def findTheDifference(self, s: str, t: str) -> str: return[i for i in t if s.count(i) != t.count(i)][0]
find-the-difference
python one line
seifsoliman
0
4
find the difference
389
0.603
Easy
6,728
https://leetcode.com/problems/find-the-difference/discuss/2770114/Python3-Simple-beginners-approach.-Please-upvote-if-it-helped
class Solution: def findTheDifference(self, s: str, t: str) -> str: temp = {} for letter in s: if letter in temp: temp[letter] += 1 else: temp[letter] = 1 letters = {} for letter in t: if letter not in temp: return letter else: if letter in letters: letters[letter] += 1 else: letters[letter] = 1 if letters[letter] > temp[letter]: return letter
find-the-difference
Python3 Simple beginners approach. Please upvote if it helped
OGLearns
0
4
find the difference
389
0.603
Easy
6,729
https://leetcode.com/problems/find-the-difference/discuss/2738653/Simple-Python-Solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: arr = list(t) for i in range(len(s)): arr.remove(s[i]) return arr[0]
find-the-difference
Simple Python Solution
dnvavinash
0
7
find the difference
389
0.603
Easy
6,730
https://leetcode.com/problems/find-the-difference/discuss/2736496/Python-Solution-93.86-faster-TC-O(n)-Space-O(1)
class Solution: def findTheDifference(self, s: str, t: str) -> str: ans = 0 #iterating over the list 1 and performing XOR for i in s: # converting the element to its ascii value for XOR ans^=ord(i) for j in t: ans^=ord(j) # converting the extra element back to its character from ascii value return chr(ans)
find-the-difference
Python Solution 93.86% faster TC O(n) Space O(1)
nidhi_nishad26
0
6
find the difference
389
0.603
Easy
6,731
https://leetcode.com/problems/find-the-difference/discuss/2735628/Python-solution-Faster-than-9818-using-Counters
class Solution: def findTheDifference(self, s: str, t: str) -> str: Cs=Counter(s) Ct=Counter(t) return list((Ct-Cs).keys())[0]
find-the-difference
Python solution Faster than 98,18%, using Counters
irouis
0
4
find the difference
389
0.603
Easy
6,732
https://leetcode.com/problems/find-the-difference/discuss/2732694/easy-approach-using-python
class Solution: def findTheDifference(self, s: str, t: str) -> str: s = sorted(list(s)) t = sorted(list(t)) for i in range(len(s)): if s[i]!=t[i]: return t[i] return t[-1]
find-the-difference
easy approach using python
sindhu_300
0
2
find the difference
389
0.603
Easy
6,733
https://leetcode.com/problems/find-the-difference/discuss/2732362/Python-(2-line-Code)
class Solution: def findTheDifference(self, s: str, t: str) -> str: for i in t: if s.count(i)!=t.count(i): return i
find-the-difference
Python (2 line Code)
durgaraopolamarasetti
0
6
find the difference
389
0.603
Easy
6,734
https://leetcode.com/problems/find-the-difference/discuss/2721715/Python-Solution-Using-hashmap
class Solution: def findTheDifference(self, s: str, t: str) -> str: sHash = {} tHash = {} for char in s: if char in sHash: sHash[char] += 1 else: sHash[char] = 1 for char in t: if char in tHash: tHash[char] += 1 else: tHash[char] = 1 for key in tHash: if key in sHash and sHash[key] == tHash[key]: continue return key
find-the-difference
Python Solution Using hashmap
Furat
0
9
find the difference
389
0.603
Easy
6,735
https://leetcode.com/problems/find-the-difference/discuss/2699340/Python-easy-solution
class Solution: def findTheDifference(self, s: str, t: str) -> str: s_arr = list(s) s_arr.sort() t_arr = list(t) t_arr.sort() for i in range(len(t_arr)-1): if t_arr[i]!=s_arr[i]: return t_arr[i] return t_arr[len(t_arr)-1]
find-the-difference
Python easy solution
dyussenovaanel
0
7
find the difference
389
0.603
Easy
6,736
https://leetcode.com/problems/find-the-difference/discuss/2693125/easy-solytion-using-XOR
class Solution: def findTheDifference(self, s: str, t: str) -> str: KeyNo = 0 for i in s: KeyNo ^= ord(i) for i in t: KeyNo ^= ord(i) return chr(KeyNo)
find-the-difference
easy solytion using XOR
algoon2002
0
3
find the difference
389
0.603
Easy
6,737
https://leetcode.com/problems/find-the-difference/discuss/2690706/PYTHON3-FASTEST
class Solution: def findTheDifference(self, s: str, t: str) -> str: for i in t: if s.count(i)!=t.count(i): return i
find-the-difference
PYTHON3 FASTEST
Gurugubelli_Anil
0
2
find the difference
389
0.603
Easy
6,738
https://leetcode.com/problems/elimination-game/discuss/824126/Python3-3-line-O(logN)
class Solution: def lastRemaining(self, n: int) -> int: if n == 1: return 1 if n&amp;1: n -= 1 return n + 2 - 2*self.lastRemaining(n//2)
elimination-game
[Python3] 3-line O(logN)
ye15
5
588
elimination game
390
0.465
Medium
6,739
https://leetcode.com/problems/elimination-game/discuss/824126/Python3-3-line-O(logN)
class Solution: def lastRemaining(self, n: int) -> int: def fn(n): """Return the final number of a list of length n.""" if n == 1: return 1 if n&amp;1: n -= 1 return n + 2*(1 - fn(n//2)) return fn(n)
elimination-game
[Python3] 3-line O(logN)
ye15
5
588
elimination game
390
0.465
Medium
6,740
https://leetcode.com/problems/elimination-game/discuss/824126/Python3-3-line-O(logN)
class Solution: def lastRemaining(self, n: int) -> int: i, di = 0, 2 for _ in range(n-1): if not 0 <= i+di < n: i += di//2 if 0 <= i + di//2 < n else -di//2 di *= -2 else: i += di return i+1
elimination-game
[Python3] 3-line O(logN)
ye15
5
588
elimination game
390
0.465
Medium
6,741
https://leetcode.com/problems/elimination-game/discuss/1016735/Python3-O(logN)-and-constant-space
class Solution: def lastRemaining(self, n: int) -> int: first=1 distance=1 step=0 while n>1: if step%2==0 or n%2!=0: first+=distance # Multiply distance by 2 distance=distance<<1 step+=1 # Divide n by 2 n=n>>1 return first
elimination-game
Python3 O(logN) and constant space
bindhushreehr
1
492
elimination game
390
0.465
Medium
6,742
https://leetcode.com/problems/elimination-game/discuss/2733788/Detail-1-line-python-explanations
class Solution: def lastRemaining(self, n: int) -> int: # explanation # F algorithem is take the even index element from the list and reverse the list # lastRemaining(9) = F([1, 2, 3, 4, 5, 6, 7, 8, 9]) # first round: F([2, 4, 6, 8]) = F(2 * [1, 2, 3, 4]) = 2 * F([4, 3, 2, 1]) # convert F([4, 3, 2, 1]) = F([3, 1]) # now we need to convert F[(3, 1)] to F([1, 3]), which is the original order then do F algorithm # 4 - 4 + 1 = 1 # 4 - 2 + 1 = 3 # n//2 - F(n//2) + 1 # base case is 1 return 2 * (n // 2 - self.lastRemaining(n//2) + 1) if n != 1 else 1
elimination-game
Detail 1-line python explanations
jackson-cmd
0
24
elimination game
390
0.465
Medium
6,743
https://leetcode.com/problems/elimination-game/discuss/2723369/Simple-recursive-solution-(beat-95-TC-beat-97-SC)
class Solution: def lastRemaining(self, n: int) -> int: if n < 3: return n if n % 2 == 1: return self.lastRemaining(n-1) elif n % 4 == 2: return 4 * self.lastRemaining((n-2)//4) else: return 4 * self.lastRemaining(n//4) - 2
elimination-game
Simple recursive solution (beat 95% TC, beat 97% SC)
zhaoqiang
0
22
elimination game
390
0.465
Medium
6,744
https://leetcode.com/problems/elimination-game/discuss/2642590/python3
class Solution: def lastRemaining(self, n: int) -> int: ans = 1 k, cnt, step = 0, n, 1 while cnt > 1: if k % 2 == 0: ans += step else: if cnt % 2: ans += step k += 1 cnt >>= 1 step <<= 1 return ans
elimination-game
python3
xy01
0
134
elimination game
390
0.465
Medium
6,745
https://leetcode.com/problems/elimination-game/discuss/2316855/C%2B%2B-solution
class Solution: def lastRemaining(self, n: int) -> int: beg = 1 len = n d = 1 fromleft = True while len > 1: if(fromleft or len%2 == 1): beg += d d <<= 1 len >>= 1 fromleft = not fromleft return beg
elimination-game
C++ solution
487o
0
192
elimination game
390
0.465
Medium
6,746
https://leetcode.com/problems/elimination-game/discuss/514388/Python3-different-simple-solutions
class Solution: def lastRemaining(self, n: int) -> int: return 1 if n==1 else 2*(1+n//2-self.lastRemaining(n//2)) def lastRemaining1(self, n: int) -> int: """" removing from left to right [1 2 3 4 5 6 7 8 9]==[2 4 6 8]==2*[1 2 3 4] """ def helper(n,is_left): if n == 1: return 1 if is_left: return 2*helper(n//2,False) if n%2==1: return 2*helper(n//2,True) return 2*helper(n//2,2)-1 return helper(n,True) def lastRemaining2(self, n: int) -> int: if n==0: return st1,st2,left=list(range(1,n+1)),[],True while len(st1)>1: if not left: st1=st1[::-1] for i in range(1,len(st1),2): st2.append(st1[i]) st1=list(st2) if left else list(st2[::-1]) st2=[] left = not left return st1[0]
elimination-game
Python3 different simple solutions
jb07
0
379
elimination game
390
0.465
Medium
6,747
https://leetcode.com/problems/perfect-rectangle/discuss/968076/Python-Fast-and-clear-solution-with-explanation
class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: area = 0 corners = set() a = lambda: (Y-y) * (X-x) for x, y, X, Y in rectangles: area += a() corners ^= {(x,y), (x,Y), (X,y), (X,Y)} if len(corners) != 4: return False x, y = min(corners, key=lambda x: x[0] + x[1]) X, Y = max(corners, key=lambda x: x[0] + x[1]) return a() == area
perfect-rectangle
[Python] Fast and clear solution with explanation
modusV
40
1,200
perfect rectangle
391
0.325
Hard
6,748
https://leetcode.com/problems/perfect-rectangle/discuss/2666778/Python-soluton
class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: xs=[] ys=[] for sx,sy,ex,ey in rectangles: xs.append(sx) xs.append(ex) ys.append(sy) ys.append(ey) xlookup={x:i for i,x in enumerate(sorted(set(xs)))} ylookup={y:i for i,y in enumerate(sorted(set(ys)))} N=len(xlookup)-1 M=len(ylookup)-1 grid=[[0]*M for _ in range(N)] for sx,sy,ex,ey in rectangles: for cx in range(xlookup[sx],xlookup[ex]): for cy in range(ylookup[sy],ylookup[ey]): grid[cx][cy]+=1 for row in grid: for cell in row: if cell!=1: return False return True
perfect-rectangle
Python soluton
Motaharozzaman1996
0
8
perfect rectangle
391
0.325
Hard
6,749
https://leetcode.com/problems/perfect-rectangle/discuss/2629231/Straightforward-Python-Solution
class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: X1, Y1 = float('inf'), float('inf') X2, Y2 = float('-inf'), float('-inf') # keeps track of the vertices that appear 1 or 3 times and eliminates those appearing 2 or 4 times points = set() actual_area = 0 for x1, y1, x2, y2 in rectangles: # find 4 vertices of the perfect rectangle X1, Y1 = min(X1, x1), min(Y1, y1) X2, Y2 = max(X2, x2), max(Y2, y2) actual_area += (x2 - x1) * (y2 - y1) vertices = [(x1, y1), (x1, y2), (x2, y1), (x2, y2)] for v in vertices: if v in points: points.remove(v) else: points.add(v) # check if actual_area is equal to expected_area expected_area = (X2 - X1) * (Y2 - Y1) if (actual_area != expected_area): return False # checks if there are four vertices left in the points set if (len(points) != 4): return False # checks if four vertices correspond to the actual perfect rectangle if (X1, Y1) not in points or (X2, Y1) not in points or (X1, Y2) not in points or (X2, Y2) not in points: return False return True
perfect-rectangle
Straightforward Python Solution
leqinancy
0
14
perfect rectangle
391
0.325
Hard
6,750
https://leetcode.com/problems/perfect-rectangle/discuss/1102039/Python3-locate-the-corners
class Solution: def isRectangleCover(self, rectangles: List[List[int]]) -> bool: area = 0 corner = set() X0 = Y0 = inf X1 = Y1 = -inf for x0, y0, x1, y1 in rectangles: area += (x1-x0)*(y1-y0) X0 = min(x0, X0) Y0 = min(y0, Y0) X1 = max(x1, X1) Y1 = max(y1, Y1) corner ^= {(x0, y0), (x0, y1), (x1, y0), (x1, y1)} return area == (X1-X0)*(Y1-Y0) and corner == {(X0, Y0), (X0, Y1), (X1, Y0), (X1, Y1)}
perfect-rectangle
[Python3] locate the corners
ye15
0
280
perfect rectangle
391
0.325
Hard
6,751
https://leetcode.com/problems/is-subsequence/discuss/2473010/Very-Easy-oror-100-oror-Fully-Explained-oror-Java-C%2B%2B-Python-JS-C-Python3-(Two-Pointers-Approach)
class Solution(object): def isSubsequence(self, s, t): # Base case if not s: return True i = 0 # Traverse elements of t string for j in t: # If this index matches to the index of s string, increment i pointer... if j == s[i]: i += 1 # If the pointer is equal to the size of s... if i == len(s): break return i == len(s)
is-subsequence
Very Easy || 100% || Fully Explained || Java, C++, Python, JS, C, Python3 (Two-Pointers Approach)
PratikSen07
16
998
is subsequence
392
0.49
Easy
6,752
https://leetcode.com/problems/is-subsequence/discuss/1811624/Simple-2-Pointer-Python-Solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i, j, n, m = 0, 0, len(s), len(t) while i < n and j < m: # Loop till any of the strings is fully traversed if s[i] == t[j]: # If char at i and j are equal then update i i += 1 # Could also write i += s[i]==t[j] j += 1 # Update j always. return i == n
is-subsequence
Simple 2 Pointer Python Solution
anCoderr
10
831
is subsequence
392
0.49
Easy
6,753
https://leetcode.com/problems/is-subsequence/discuss/2679763/Python-Easy-Solution-or-99-Faster-or-Is-Subsequence
class Solution: def isSubsequence(self, s: str, t: str) -> bool: sl, tl = 0, 0 while sl<len(s) and tl<len(t): if s[sl] == t[tl]: sl+=1 tl+=1 else: tl+=1 if sl==len(s): return True else: return False
is-subsequence
✔️ Python Easy Solution | 99% Faster | Is Subsequence
pniraj657
9
745
is subsequence
392
0.49
Easy
6,754
https://leetcode.com/problems/is-subsequence/discuss/1077869/Python.-faster-than-99.45.-Easy-understanding-solution.
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i, j, m, n = 0, 0, len(s), len(t) while i < m and j < n and n - j >= m - i: if s[i] == t[j]: i += 1 j += 1 return i == m
is-subsequence
Python. faster than 99.45%. Easy-understanding solution.
m-d-f
5
736
is subsequence
392
0.49
Easy
6,755
https://leetcode.com/problems/is-subsequence/discuss/423566/Python3-4-solutions-(quickest-99.98-shortest-two-lines)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: it = iter(t) return all(ch in it for ch in s)
is-subsequence
[Python3] 4 solutions (quickest 99.98%, shortest two lines)
ye15
5
422
is subsequence
392
0.49
Easy
6,756
https://leetcode.com/problems/is-subsequence/discuss/423566/Python3-4-solutions-(quickest-99.98-shortest-two-lines)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: k = 0 for c in s: k = t.find(c, k) + 1 if k == 0: return False return True
is-subsequence
[Python3] 4 solutions (quickest 99.98%, shortest two lines)
ye15
5
422
is subsequence
392
0.49
Easy
6,757
https://leetcode.com/problems/is-subsequence/discuss/423566/Python3-4-solutions-(quickest-99.98-shortest-two-lines)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: k = 0 for c in s: try: k = t.index(c, k) + 1 except: return False return True
is-subsequence
[Python3] 4 solutions (quickest 99.98%, shortest two lines)
ye15
5
422
is subsequence
392
0.49
Easy
6,758
https://leetcode.com/problems/is-subsequence/discuss/423566/Python3-4-solutions-(quickest-99.98-shortest-two-lines)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i = 0 for c in t: if i < len(s) and s[i] == c: i += 1 return i == len(s)
is-subsequence
[Python3] 4 solutions (quickest 99.98%, shortest two lines)
ye15
5
422
is subsequence
392
0.49
Easy
6,759
https://leetcode.com/problems/is-subsequence/discuss/2126747/Python-or-One-of-the-most-elegant-solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: for char in t: if len(s) > 0 and char == s[0]: s = s[1:] return len(s) == 0
is-subsequence
Python | One of the most elegant solution
__Asrar
3
96
is subsequence
392
0.49
Easy
6,760
https://leetcode.com/problems/is-subsequence/discuss/1811501/Pythonic-O(n)-Iterative-Solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i,j=0,0 while(j<len(s) and i<len(t)): if(s[j]==t[i]): j+=1 i+=1 return j==len(s)
is-subsequence
Pythonic O(n) Iterative Solution
js5809
3
134
is subsequence
392
0.49
Easy
6,761
https://leetcode.com/problems/is-subsequence/discuss/1197645/Python-DP-Standard-Solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: n = len(s) m = len(t) if n==0: return True if m==0: return False dp = [[0 for _ in range(n+1)] for _ in range(m+1)] for i in range(1,m+1): for j in range(1,n+1): if t[i-1] == s[j-1]: dp[i][j] = dp[i-1][j-1] + 1 else: dp[i][j] = max(dp[i-1][j],dp[i][j-1]) if dp[i][j] == len(s): return True return False
is-subsequence
Python DP Standard Solution
iamkshitij77
3
136
is subsequence
392
0.49
Easy
6,762
https://leetcode.com/problems/is-subsequence/discuss/380060/Solution-in-Python-3-(beats-~100)-(five-lines)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: I = -1 for i in s: I = t.find(i,I+1) if I == -1: return False return True - Junaid Mansuri (LeetCode ID)@hotmail.com
is-subsequence
Solution in Python 3 (beats ~100%) (five lines)
junaidmansuri
3
672
is subsequence
392
0.49
Easy
6,763
https://leetcode.com/problems/is-subsequence/discuss/2770032/The-most-readable-solution-in-Python-for-%22392.-Is-subsequence%22
class Solution: def isSubsequence(self, s: str, t: str) -> bool: n = len(s) j = 0 for letter in t: if j == n: return True if letter == s[j]: j += 1 return j == n
is-subsequence
The most readable solution in Python for "392. Is subsequence"
bekbull
2
169
is subsequence
392
0.49
Easy
6,764
https://leetcode.com/problems/is-subsequence/discuss/1813856/Python3-oror-Linear-Solution-oror-Almost-100-Faster
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) > len(t): return False j = 0 for i in t: if j < len(s): if i == s[j]: j += 1 return True if j == len(s) else False
is-subsequence
Python3 || Linear Solution || Almost 100% Faster
cherrysri1997
2
83
is subsequence
392
0.49
Easy
6,765
https://leetcode.com/problems/is-subsequence/discuss/1811282/Python-Simple-Python-Solution-With-Two-Pointers
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i=0 j=0 while i<len(s) and j<len(t): if s[i]==t[j]: i=i+1 j=j+1 else: j=j+1 if i==len(s): return True else: return False
is-subsequence
[ Python ] ✔✔ Simple Python Solution With Two Pointers 🔥✌
ASHOK_KUMAR_MEGHVANSHI
2
183
is subsequence
392
0.49
Easy
6,766
https://leetcode.com/problems/is-subsequence/discuss/1496681/Difference-between-Subarray-or-Subsequence-or-Subset-oror-Beginner-Approach
class Solution: def isSubsequence(self, s: str, t: str) -> bool: # A very intuitive way to check if one is a subsequence of other or not # Here, We will check if s is a subsequence of t or not i=0 #to keep a check of elements across s j=0 #to keep a check of elements across t while(j < len(t) and i < len(s)): if (s[i] == t[j]): i += 1 j += 1 else: j+=1 if(i == len(s)): #it means s is a subsequence of t as i covered all elements of s across t return True else: return False
is-subsequence
Difference between Subarray | Subsequence | Subset || Beginner Approach
aarushsharmaa
2
126
is subsequence
392
0.49
Easy
6,767
https://leetcode.com/problems/is-subsequence/discuss/2573596/SIMPLE-PYTHON3-SOLUTION-O(t)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s)==0:return True count = 0 for i in range(len(t)): if count <= len(s) - 1: if s[count] == t[i]: count += 1 return count == len(s)
is-subsequence
✅✔ SIMPLE PYTHON3 SOLUTION ✅✔O(t)
rajukommula
1
67
is subsequence
392
0.49
Easy
6,768
https://leetcode.com/problems/is-subsequence/discuss/2483813/Runtime%3A-56-ms-faster-than-38.48-of-Python3-Memory-Usage%3A-13.9-MB-less-than-43.43-of-Python3
class Solution: def isSubsequence(self, s: str, t: str) -> bool: for i in range(0,len(t)): if len(s)==0: return True elif t[i]==s[0]: s=s[1:] return len(s)==0
is-subsequence
Runtime: 56 ms, faster than 38.48% of Python3 ,Memory Usage: 13.9 MB, less than 43.43% of Python3
DG-Problemsolver
1
6
is subsequence
392
0.49
Easy
6,769
https://leetcode.com/problems/is-subsequence/discuss/2327519/Python3-O(n%2Bm)-oror-O(1)-Runtime%3A-38ms-83.94-oror-memory%3A-13.8mb-82.20
class Solution: # O(n+m) || O(1) # Runtime: 38ms 83.94% || memory: 13.8mb 82.20% def isSubsequence(self, string: str, target: str) -> bool: i = 0 for char in target: if i == len(string): return True if char == string[i]: i += 1 return i == len(string)
is-subsequence
Python3 O(n+m) || O(1) # Runtime: 38ms 83.94% || memory: 13.8mb 82.20%
arshergon
1
36
is subsequence
392
0.49
Easy
6,770
https://leetcode.com/problems/is-subsequence/discuss/2279444/Python3-two-pointers-approach
class Solution: def isSubsequence(self, s: str, t: str) -> bool: first = 0 second = 0 while first<len(s) and second<len(t): if s[first]==t[second]: first+=1 second+=1 return first>=len(s)
is-subsequence
📌 Python3 two pointers approach
Dark_wolf_jss
1
32
is subsequence
392
0.49
Easy
6,771
https://leetcode.com/problems/is-subsequence/discuss/1930728/Two-Pointer-Approach
class Solution: def isSubsequence(self, s: str, t: str) -> bool: # initialize pointers pointer_1, pointer_2 = 0, 0 # to ensure pointers traverse till the end of both strings while pointer_1 < len(s) and pointer_2 <len(t): # if both the pointers are pointing to same element, just shift the pointers to next position if s[pointer_1] == t[pointer_2]: pointer_1 += 1 pointer_2 += 1 # otherwise, just shift the right pointer by one position keeping left intact else: pointer_2 += 1 return pointer_1 == len(s)
is-subsequence
Two Pointer Approach
Jayesh_Suryavanshi
1
43
is subsequence
392
0.49
Easy
6,772
https://leetcode.com/problems/is-subsequence/discuss/1847339/Python-easy-solution-beats-96
class Solution: def isSubsequence(self, s: str, t: str) -> bool: left, right = 0, 0 while left != len(s) and right != len(t) : if s[left] != t[right]: right += 1 elif s[left] == t[right]: left += 1 right += 1 if left == len(s): return True return False
is-subsequence
Python easy solution beats 96%
yusianglin11010
1
101
is subsequence
392
0.49
Easy
6,773
https://leetcode.com/problems/is-subsequence/discuss/1813489/Python-Queue-Solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) == 0: return True q = [c for c in s] for c in t: if q[0] == c: q.pop(0) if len(q) == 0: return True return False
is-subsequence
Python Queue Solution
Pootato
1
20
is subsequence
392
0.49
Easy
6,774
https://leetcode.com/problems/is-subsequence/discuss/1811595/Self-understandable-Python-%3A
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s)>len(t): return False if len(s)==0: return True j=0 p="" for i in t: if i==s[j]: p+=i j+=1 if j>=len(s): break return p==s
is-subsequence
Self understandable Python :
goxy_coder
1
81
is subsequence
392
0.49
Easy
6,775
https://leetcode.com/problems/is-subsequence/discuss/1370625/2-pointer-solution-or-Python
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i,j = 0,0 if(len(s)>len(t)): return False while( i<len(s) and j<len(t) ): if(s[i] == t[j]): i+=1 j+=1 else: j+=1 if(i == len(s)): return True return False
is-subsequence
2 pointer solution | Python
RishithaRamesh
1
74
is subsequence
392
0.49
Easy
6,776
https://leetcode.com/problems/is-subsequence/discuss/1079112/Python-solution-using-while-and-for-loop.
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) > len(t): return False i, j = 0, 0 while i < len(s) and j < len(t): if s[i] == t[j]: i += 1 j += 1 if len(s) == i: return True return False
is-subsequence
Python solution using while and for loop.
vsahoo
1
80
is subsequence
392
0.49
Easy
6,777
https://leetcode.com/problems/is-subsequence/discuss/679493/python-two-pointers-and-NlogN-follow-up-by-binary-search
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i = j = 0 while i < len(s) and j < len(t): if s[i] == t[j]: i+=1 j+=1 else: j+=1 return i == len(s)
is-subsequence
python two pointers and NlogN follow-up by binary search
nightybear
1
86
is subsequence
392
0.49
Easy
6,778
https://leetcode.com/problems/is-subsequence/discuss/679493/python-two-pointers-and-NlogN-follow-up-by-binary-search
class Solution: ''' Time complexity : O(nlogn) Space complexity : O(n) ''' def isSubsequence(self, s: str, t: str) -> bool: indexs = collections.defaultdict(list) for idx, x in enumerate(t): indexs[x].append(idx) prev = 0 for x in s: i = bisect.bisect_left(indexs[x], prev) if i == len(indexs[x]): return False prev = indexs[x][i]+1 return True
is-subsequence
python two pointers and NlogN follow-up by binary search
nightybear
1
86
is subsequence
392
0.49
Easy
6,779
https://leetcode.com/problems/is-subsequence/discuss/2848574/python3
class Solution: def isSubsequence(self, s: str, t: str) -> bool: idx = 0 for c in s: idx = t.find(c, idx) if idx == -1: return False idx += 1 return True
is-subsequence
python3
wduf
0
1
is subsequence
392
0.49
Easy
6,780
https://leetcode.com/problems/is-subsequence/discuss/2846740/Easy-understand-python-solution-(beginer-friendly)
class Solution: def isSubsequence(self, s: str, t: str) -> bool: count=0 if not s : return True if not t: return False for ele in t: if ele==s[count]: count+=1 if count==len(s): return True return False
is-subsequence
Easy understand python solution (beginer friendly)
amangarg0599
0
1
is subsequence
392
0.49
Easy
6,781
https://leetcode.com/problems/is-subsequence/discuss/2838020/Python3-solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: position = -1 for char in s: position = t.find(char, position + 1) if position == -1: return False return True
is-subsequence
Python3 solution
arthur54342
0
3
is subsequence
392
0.49
Easy
6,782
https://leetcode.com/problems/is-subsequence/discuss/2835462/Simple-One-Pass-O(1)-space-with-two-pointers
class Solution: def isSubsequence(self, s: str, t: str) -> bool: p1 = p2 = 0 while p1 < len(s) and p2 < len(t): if s[p1] == t[p2]: p1 += 1 p2 += 1 return p1 == len(s)
is-subsequence
Simple One Pass O(1) space with two pointers
WhyYouCryingMama
0
2
is subsequence
392
0.49
Easy
6,783
https://leetcode.com/problems/is-subsequence/discuss/2835461/Simple-One-Pass-O(1)-space-with-two-pointers
class Solution: def isSubsequence(self, s: str, t: str) -> bool: p1 = p2 = 0 while p1 < len(s) and p2 < len(t): if s[p1] == t[p2]: p1 += 1 p2 += 1 return p1 == len(s)
is-subsequence
Simple One Pass O(1) space with two pointers
WhyYouCryingMama
0
0
is subsequence
392
0.49
Easy
6,784
https://leetcode.com/problems/is-subsequence/discuss/2835150/Python3-Simple-Clean-Code
class Solution: def isSubsequence(self, s: str, t: str) -> bool: for i in range(len(s)): findIndex = t.find(s[i]) if s[i] in t else -1 if findIndex == -1: return False t = t[findIndex+1:] return True
is-subsequence
✅ Python3 Simple Clean Code
Cecilia_GuoChen
0
3
is subsequence
392
0.49
Easy
6,785
https://leetcode.com/problems/is-subsequence/discuss/2835046/My-python-solution-or-beats-90
class Solution: def isSubsequence(self, s: str, t: str) -> bool: for e in s: if e not in t: return False i = 0 j = 0 while j < len(t): if i <len(s) and s[i] ==t[j]: i+=1 j+=1 return i == len(s)
is-subsequence
My python solution | beats 90%
sahil193101
0
4
is subsequence
392
0.49
Easy
6,786
https://leetcode.com/problems/is-subsequence/discuss/2829435/Python-or-Two-Pointer-or-Merge-two-array-way
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if not s: return True if len(s) > len(t): return False end = len(t)-1 first_end = len(s)-1 t_start = 0 s_start = 0 while t_start <= end and s_start <= first_end: if s[s_start] == t[t_start]: s_start += 1 t_start += 1 else: t_start += 1 if s_start < len(s): return False return True
is-subsequence
Python | Two Pointer | Merge two array way
ajay_gc
0
5
is subsequence
392
0.49
Easy
6,787
https://leetcode.com/problems/is-subsequence/discuss/2828195/Two-Pointers-easy
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i=0 j=0 if len(s)>len(t) or (len(t)==0 and len(s)!=0): return False if len(s)==0: return True for i in range(len(t)): if s[j]==t[i]: j+=1 if j==len(s): return True return False
is-subsequence
Two Pointers easy
rhi_1
0
2
is subsequence
392
0.49
Easy
6,788
https://leetcode.com/problems/is-subsequence/discuss/2819037/Python-My-O(n)-Solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if not s: return True if not t: return False s_pointer = 0 for t_char in t: if t_char == s[s_pointer]: s_pointer += 1 if s_pointer == len(s): return True return False
is-subsequence
[Python] My O(n) Solution
manytenks
0
3
is subsequence
392
0.49
Easy
6,789
https://leetcode.com/problems/is-subsequence/discuss/2818144/two-pointer-and-some-conclutions
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) < 1:return True if len(s) > len(t):return False s_pointer = 0 for t_pointer in range(0,len(t)): if s_pointer <= len(s)-1: if s[s_pointer]==t[t_pointer]:s_pointer += 1 return s_pointer == len(s)
is-subsequence
two pointer and some conclutions
roger880327
0
1
is subsequence
392
0.49
Easy
6,790
https://leetcode.com/problems/is-subsequence/discuss/2818113/using-two-pointers
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) < 1:return True s_pointer = 0 for t_pointer in range(0,len(t)): if s_pointer < len(s): if s[s_pointer]==t[t_pointer]:s_pointer += 1 if s_pointer == 0:return False return s_pointer == len(s)
is-subsequence
using two pointers
roger880327
0
1
is subsequence
392
0.49
Easy
6,791
https://leetcode.com/problems/is-subsequence/discuss/2816077/Python-o(n)-solution-simple-to-understand
class Solution: def isSubsequence(self, s: str, t: str) -> bool: i = 0 for c in s: while i < len(t) and t[i] != c: i+= 1 if i == len(t): return False i+=1 return True
is-subsequence
Python o(n) solution, simple to understand
pradyumna04
0
1
is subsequence
392
0.49
Easy
6,792
https://leetcode.com/problems/is-subsequence/discuss/2807838/easy-understnding-python
class Solution: def isSubsequence(self, s: str, t: str) -> bool: counter = 0 for c in s: if c in t: t = t[t.index(c) + 1:] counter += 1 if len(s) == counter: return True return False
is-subsequence
easy understnding python
don_masih
0
2
is subsequence
392
0.49
Easy
6,793
https://leetcode.com/problems/is-subsequence/discuss/2799242/Subsequence-My-Solution
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) == 0: return True si, ti = 0,0 for ti in range(len(t)): if s[si] == t[ti]: si += 1 if si == len(s): return True return False
is-subsequence
Subsequence - My Solution
marked01one
0
2
is subsequence
392
0.49
Easy
6,794
https://leetcode.com/problems/is-subsequence/discuss/2796564/Is-Substring-Python-easy-to-understand-beginner-friendly-comments
class Solution: def isSubsequence(self, s: str, t: str) -> bool: """ Using a 2-pointer approach, compare two strings and determines if the first string is a subset of the second string. :param s: str: String of alpha characters :param t: str: String of alpha characters :return bool: True if first string is a contiguous subset of the second string """ # Set variables equal to the length of each input string left_bound, right_bound = len(s), len(t) # Initialize index for each pointer p_left = p_right = 0 while p_left < left_bound and p_right < right_bound: # Move both pointers if the equal each other if s[p_left] == t[p_right]: p_left += 1 p_right += 1 # Return when left pointer equals length of source string return p_left == left_bound
is-subsequence
Is Substring - Python, easy-to-understand, beginner friendly, comments
mthomp89
0
1
is subsequence
392
0.49
Easy
6,795
https://leetcode.com/problems/is-subsequence/discuss/2790867/Simple-solution-using-exception-to-catch-completed-substring
class Solution: def isSubsequence(self, s: str, t: str) -> bool: # Make an iterator of the sub string s_iter = iter(s) try: # Start by taking the first character in the substring sub = next(s_iter) for curr in t: if curr == sub: sub = next(s_iter) # When next() is called, and s_iter is emptied, # StopIteration will be raised except StopIteration: return True return False
is-subsequence
Simple solution using exception to catch completed substring
stereo1
0
2
is subsequence
392
0.49
Easy
6,796
https://leetcode.com/problems/is-subsequence/discuss/2786048/Easy-python-solution-or-Is-Subsequence
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(t) < len(s): return False for i in range(len(t)): if len(s) > 0 and t[i] == s[0]: s = s[1:] if len(s) == 0: return True return False
is-subsequence
Easy python solution | Is Subsequence
nishanrahman1994
0
2
is subsequence
392
0.49
Easy
6,797
https://leetcode.com/problems/is-subsequence/discuss/2786047/Easy-python-solution-or-Is-Subsequence
class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(t) < len(s): return False for i in range(len(t)): if len(s) > 0 and t[i] == s[0]: s = s[1:] if len(s) == 0: return True return False
is-subsequence
Easy python solution | Is Subsequence
nishanrahman1994
0
1
is subsequence
392
0.49
Easy
6,798
https://leetcode.com/problems/is-subsequence/discuss/2784933/Pretty-happy-i-managed-to-get-a-pretty-good-solution-on-my-own-for-once.
class Solution: def isSubsequence(self, s: str, t: str) -> bool: len_s = len(s) if len_s == 0: return True i: int = 0 for char in t: if s[i] == char: i += 1 if i == len_s: return True return False
is-subsequence
Pretty happy i managed to get a pretty good solution on my own for once.
Seawolf159
0
1
is subsequence
392
0.49
Easy
6,799