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/coin-change-ii/discuss/675186/Python3-DP-Solution-O(mn)-Time-and-Space | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [[1]+[0]*amount for _ in range(len(coins)+1)]
for i in range(1, len(coins)+1):
for j in range(1, amount+1):
if coins[i-1] <= j:
dp[i][j] = dp[i-1][j] + dp[i][j-coins[i-1]]
... | coin-change-ii | Python3 DP Solution - O(mn) Time and Space | schedutron | 9 | 1,200 | coin change ii | 518 | 0.599 | Medium | 9,100 |
https://leetcode.com/problems/coin-change-ii/discuss/676538/Python3-dp | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [1] + [0]*amount
for coin in coins:
for x in range(coin, amount+1):
dp[x] += dp[x-coin]
return dp[-1] | coin-change-ii | [Python3] dp | ye15 | 5 | 399 | coin change ii | 518 | 0.599 | Medium | 9,101 |
https://leetcode.com/problems/coin-change-ii/discuss/676538/Python3-dp | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [1] + [0]*amount
for coin in coins:
for x in range(amount-coin+1):
dp[x+coin] += dp[x]
return dp[-1] | coin-change-ii | [Python3] dp | ye15 | 5 | 399 | coin change ii | 518 | 0.599 | Medium | 9,102 |
https://leetcode.com/problems/coin-change-ii/discuss/676538/Python3-dp | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
coins.sort(reverse=True)
@lru_cache(None)
def fn(i, target):
"""Return number of number of combo in coins[i:] to make up target"""
if target < 0: return 0
if target == 0: retu... | coin-change-ii | [Python3] dp | ye15 | 5 | 399 | coin change ii | 518 | 0.599 | Medium | 9,103 |
https://leetcode.com/problems/coin-change-ii/discuss/272620/python-3-dp | class Solution:
def change(self, amount, coins):
dp = [0] * (amount + 1)
dp[0] = 1
for i in coins:
for j in range(amount+1):
if j >= i:
dp[j] += dp[j-i]
return dp[-1] | coin-change-ii | python 3 dp | xiangyupeng1994 | 4 | 547 | coin change ii | 518 | 0.599 | Medium | 9,104 |
https://leetcode.com/problems/coin-change-ii/discuss/676672/DFS-with-memorizationPython-or-Beat-42-or-Easy-to-understand | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
# Sort first
coins.sort(reverse=True)
# Map to save the solution count
self.map = {}
return self.dfs(coins, 0, amount)
def dfs(self, coins, index, target):
# Find a ... | coin-change-ii | DFS with memorization[Python] | Beat 42% | Easy to understand | gogogoogle | 3 | 370 | coin change ii | 518 | 0.599 | Medium | 9,105 |
https://leetcode.com/problems/coin-change-ii/discuss/2623979/Explained%3A-Brute-Force-greater-MemoizationTop-Down-greater-Bottom-Up-2D-greater-Bottom-Up-1D | class Solution:
def brute(self, coins, i, target):
if target == 0:
return 1
if i >= len(coins):
return 0
coin = coins[i]
c1 = 0
if (target - coin) >= 0:
c1 = self.brute(coins, i, target - coin)
c2 = s... | coin-change-ii | Explained: Brute Force -> Memoization/Top Down -> Bottom-Up 2D -> Bottom-Up 1D | paradoxical | 2 | 74 | coin change ii | 518 | 0.599 | Medium | 9,106 |
https://leetcode.com/problems/coin-change-ii/discuss/2623979/Explained%3A-Brute-Force-greater-MemoizationTop-Down-greater-Bottom-Up-2D-greater-Bottom-Up-1D | class Solution:
def memoized(self, coins, i, target, memo):
if target == 0:
return 1
if i >= len(coins):
return 0
if memo[i][target] != None:
return memo[i][target]
coin = coins[i]
c1 = 0
if (target - coin... | coin-change-ii | Explained: Brute Force -> Memoization/Top Down -> Bottom-Up 2D -> Bottom-Up 1D | paradoxical | 2 | 74 | coin change ii | 518 | 0.599 | Medium | 9,107 |
https://leetcode.com/problems/coin-change-ii/discuss/2623979/Explained%3A-Brute-Force-greater-MemoizationTop-Down-greater-Bottom-Up-2D-greater-Bottom-Up-1D | class Solution:
def bottomUp(self, coins, target):
n = len(coins)
dp = [[0 for _ in range(target + 1)] for _ in range(n)]
for i in range(n):
dp[i][0] = 1 # when j == 0, the result is 0
coin = coins[0]
for j in range(1, target + 1):
if... | coin-change-ii | Explained: Brute Force -> Memoization/Top Down -> Bottom-Up 2D -> Bottom-Up 1D | paradoxical | 2 | 74 | coin change ii | 518 | 0.599 | Medium | 9,108 |
https://leetcode.com/problems/coin-change-ii/discuss/2623979/Explained%3A-Brute-Force-greater-MemoizationTop-Down-greater-Bottom-Up-2D-greater-Bottom-Up-1D | class Solution:
def change(self, target: int, coins: List[int]) -> int:
n = len(coins)
dp = [0 for _ in range(target + 1)]
dp[0] = 1 # Same idea as in the multi-row bottom-up DP code
for i in range(n): # simplified loop
coin = coins[i]
for j in range... | coin-change-ii | Explained: Brute Force -> Memoization/Top Down -> Bottom-Up 2D -> Bottom-Up 1D | paradoxical | 2 | 74 | coin change ii | 518 | 0.599 | Medium | 9,109 |
https://leetcode.com/problems/coin-change-ii/discuss/1834854/Python-4-approaches | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
#Backtracking--------
# ans=[0]
# def recur(i,s,ans):
# if s==amount:
# ans[0]+= 1
# return
# if s>amount or i==len(coins):
# return 0
# s+=coi... | coin-change-ii | [Python] 4 approaches | RaghavGupta22 | 2 | 334 | coin change ii | 518 | 0.599 | Medium | 9,110 |
https://leetcode.com/problems/coin-change-ii/discuss/1435056/pythonpython3-Unbounded-Knapsack-Simple-Approach | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
# initializing the dp table
n = len(coins)
dp=[[0 for j in range(amount+1)] for i in range(n+1)]
for i in range(n+1):
dp[i][0] = 1
for i in range(1, n+1):
... | coin-change-ii | [python/python3] Unbounded Knapsack-Simple Approach | nandanabhishek | 2 | 182 | coin change ii | 518 | 0.599 | Medium | 9,111 |
https://leetcode.com/problems/coin-change-ii/discuss/2434920/Python-oror-Easy-Implementation-oror-Recursion-greater-Memoization-oror-DP | class Solution(object):
def change(self, amount, coins):
"""
:type amount: int
:type coins: List[int]
:rtype: int
"""
dp={}
def A(ind,amount):
# if the (ind,amount) in dp then return the value
if (ind,amount) in dp:return dp[(ind,amoun... | coin-change-ii | Python || Easy Implementation || Recursion ---> Memoization || DP | srikarsai550 | 1 | 55 | coin change ii | 518 | 0.599 | Medium | 9,112 |
https://leetcode.com/problems/coin-change-ii/discuss/2237657/Python-runtime-84.95-memory-89.49 | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [0 for _ in range(amount+1)]
dp[0] = 1
for coin in coins:
for num in range(coin, amount+1):
dp[num] += dp[num-coin]
return dp[amount] | coin-change-ii | Python, runtime 84.95% , memory 89.49% | tsai00150 | 1 | 74 | coin change ii | 518 | 0.599 | Medium | 9,113 |
https://leetcode.com/problems/coin-change-ii/discuss/2237657/Python-runtime-84.95-memory-89.49 | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
coins.sort(reverse=True)
d = {}
return self.generateCount(amount, coins, 0, 0, d)
def generateCount(self, amount, coins, index, count, d):
if amount == 0:
return count+1
if index == l... | coin-change-ii | Python, runtime 84.95% , memory 89.49% | tsai00150 | 1 | 74 | coin change ii | 518 | 0.599 | Medium | 9,114 |
https://leetcode.com/problems/coin-change-ii/discuss/2086667/Python-Solution-by-DP | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
n=len(coins)
s=amount
dp =([[0 for i in range(s + 1)] for i in range(n + 1)])
for i in range(n+1):
for j in range(s+1):
if i==0:
dp[i][j]=0
if j==0:... | coin-change-ii | Python Solution by DP | a_dityamishra | 1 | 77 | coin change ii | 518 | 0.599 | Medium | 9,115 |
https://leetcode.com/problems/coin-change-ii/discuss/1502853/Common-Mistake-clarification-oror-Easy-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
n = len(coins)
m = [0] * (amount + 1)
a=amount
m[0]=1
for j in range(1,a+1):
for i in coins:
if i<=j:
m[j]+=m[j-i]
retu... | coin-change-ii | Common Mistake clarification || Easy Solution | nmk0462 | 1 | 188 | coin change ii | 518 | 0.599 | Medium | 9,116 |
https://leetcode.com/problems/coin-change-ii/discuss/1502853/Common-Mistake-clarification-oror-Easy-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
n = len(coins)
m = [0] * (amount + 1)
a=amount
m[0]=1
for j in coins:
for i in range(1,a+1):
if i>=j:
m[i]+=m[i-j]
retu... | coin-change-ii | Common Mistake clarification || Easy Solution | nmk0462 | 1 | 188 | coin change ii | 518 | 0.599 | Medium | 9,117 |
https://leetcode.com/problems/coin-change-ii/discuss/1500751/Python-oror-Easy-Solution-oror-using-dp | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
lst = [0] * (amount + 1)
lst[0] = 1
for i in coins:
for j in range(i, amount + 1):
lst[j] += lst[j - i]
return (lst[amount]) | coin-change-ii | Python || Easy Solution || using dp | naveenrathore | 1 | 162 | coin change ii | 518 | 0.599 | Medium | 9,118 |
https://leetcode.com/problems/coin-change-ii/discuss/1460263/PyPy3-Solution-using-unbounded-knapsack-w-comments | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
# If amount is zero, it can be achieved using
# a null set, so return 1
if not amount:
return 1
# For all other cases unbounded knapsack
def dp(n,w):
... | coin-change-ii | [Py/Py3] Solution using unbounded knapsack w/ comments | ssshukla26 | 1 | 157 | coin change ii | 518 | 0.599 | Medium | 9,119 |
https://leetcode.com/problems/coin-change-ii/discuss/1369185/Python-Simple-DP-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
ways = [0] * (amount + 1)
ways[0] = 1
for coin in coins:
for i in range(coin, len(ways)):
ways[i] += ways[i-coin]
return ways[-1] | coin-change-ii | Python Simple DP Solution | peatear-anthony | 1 | 217 | coin change ii | 518 | 0.599 | Medium | 9,120 |
https://leetcode.com/problems/coin-change-ii/discuss/2817813/python-super-easy-to-understand-dp-top-down-%2B-sorting | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
coins.sort()
@functools.lru_cache(None)
def dp(amount, i):
if amount == 0:
return 1
ans = 0
for x in range(i, len(coins)):
if coins[x] <= amou... | coin-change-ii | python super easy to understand dp top down + sorting | harrychen1995 | 0 | 8 | coin change ii | 518 | 0.599 | Medium | 9,121 |
https://leetcode.com/problems/coin-change-ii/discuss/2743030/DP-Solution-oror-Memoization-oror-Tabulation-oror-Space-Optimization | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
n = len(coins)
# SPACE OPTIMIZATION
prev = [0 for j in range(amount+1)]
curr = [0 for j in range(amount+1)]
for j in range(amount+1):
if j % coins[0] == 0:
prev[j] = 1
... | coin-change-ii | DP Solution || Memoization || Tabulation || Space Optimization | shreya_pattewar | 0 | 12 | coin change ii | 518 | 0.599 | Medium | 9,122 |
https://leetcode.com/problems/coin-change-ii/discuss/2730200/Python-3-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [1] + [0]*amount
for x in coins:
for i in range(x, amount + 1):
dp[i] += dp[i - x]
return dp[-1] | coin-change-ii | Python 3 Solution | mati44 | 0 | 8 | coin change ii | 518 | 0.599 | Medium | 9,123 |
https://leetcode.com/problems/coin-change-ii/discuss/2671906/MEMOIZATION-2D-1D-DP | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
"""
Input: Array of integers
constraints:
1. Infinite number of each coin
output: integer
1. Do I have duplicate integers in the array
2. Choose a single coin and add it ... | coin-change-ii | MEMOIZATION, 2D, 1D DP | leomensah | 0 | 65 | coin change ii | 518 | 0.599 | Medium | 9,124 |
https://leetcode.com/problems/coin-change-ii/discuss/2458996/Python-Simple-Python-Solution-100-Optimal-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dpdict = {}
def sol(i, T):
if T == 0:
return 1
if i==0:
if T%coins[i] == 0:
return 1
return 0
if (i, T) in dpdi... | coin-change-ii | [ Python ] ✅ Simple Python Solution ✅✅ ✅100% Optimal Solution | vaibhav0077 | 0 | 67 | coin change ii | 518 | 0.599 | Medium | 9,125 |
https://leetcode.com/problems/coin-change-ii/discuss/2458996/Python-Simple-Python-Solution-100-Optimal-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dpdict = {}
dp = [[-1 for i in range(amount+1)] for j in range(len(coins))]
# for i in range(amount+1):
# if i%coins[0] == 0:
# dpdict[(0, i)] =1
# else:
# ... | coin-change-ii | [ Python ] ✅ Simple Python Solution ✅✅ ✅100% Optimal Solution | vaibhav0077 | 0 | 67 | coin change ii | 518 | 0.599 | Medium | 9,126 |
https://leetcode.com/problems/coin-change-ii/discuss/2359883/Python3-Solution-with-using-dp | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [0] * (amount + 1)
dp[0] = 1
for coin in coins:
for i in range(coin, amount + 1):
dp[i] += dp[i - coin]
return dp[-1] | coin-change-ii | [Python3] Solution with using dp | maosipov11 | 0 | 31 | coin change ii | 518 | 0.599 | Medium | 9,127 |
https://leetcode.com/problems/coin-change-ii/discuss/2346429/python-easy-and-fast-solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [[0] * (len(coins) + 1) for i in range(amount + 1)]
dp[0] = [1] * (len(coins) + 1)
for a in range(1, amount + 1):
for i in range(len(coins) - 1, -1, -1):
dp[a][i] = dp[a][i + 1]
... | coin-change-ii | python easy and fast solution | soumyadexter7 | 0 | 61 | coin change ii | 518 | 0.599 | Medium | 9,128 |
https://leetcode.com/problems/coin-change-ii/discuss/2232732/Dynamic-Programming-oror-Top-Down-(Memoization)-%2B-Bottom-Up-Approaches-Explained-oror-Clean-Code | class Solution:
def countCombinations(self, amount, coins, n, dpMatrix):
for i in range(n + 1):
for j in range(amount + 1):
if i == 0:
dpMatrix[i][j] = 0
elif j == 0:
dpMatrix[i][j] = 1
else:
... | coin-change-ii | Dynamic Programming || Top Down (Memoization) + Bottom Up Approaches Explained || Clean Code | Vaibhav7860 | 0 | 49 | coin change ii | 518 | 0.599 | Medium | 9,129 |
https://leetcode.com/problems/coin-change-ii/discuss/2232732/Dynamic-Programming-oror-Top-Down-(Memoization)-%2B-Bottom-Up-Approaches-Explained-oror-Clean-Code | class Solution:
def countCombinations(self, amount, coins, n, dpMatrix):
if n == 0:
return 0
if amount == 0:
return 1
if dpMatrix[n][amount] != -1:
return dpMatrix[n][amount]
if coins[n - 1] <= amount:
dpMatri... | coin-change-ii | Dynamic Programming || Top Down (Memoization) + Bottom Up Approaches Explained || Clean Code | Vaibhav7860 | 0 | 49 | coin change ii | 518 | 0.599 | Medium | 9,130 |
https://leetcode.com/problems/coin-change-ii/discuss/2224016/Python-solution-using-DP-or-Coin-Change-2 | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [[0] * (len(coins) + 1) for i in range(amount + 1)]
dp[0] = [1] * (len(coins) + 1)
for a in range(1, amount + 1):
for i in range(len(coins) - 1, -1, -1):
dp[a][i] = dp[a][i+1]
... | coin-change-ii | Python solution using DP | Coin Change 2 | nishanrahman1994 | 0 | 26 | coin change ii | 518 | 0.599 | Medium | 9,131 |
https://leetcode.com/problems/coin-change-ii/discuss/2076841/EASIESToror-STEP-BY-STEPoror-SIMPLE | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
#Initialization of matrix
n=len(coins)
t = [[0 for _ in range(amount+2)] for _ in range(n+2)]
#1 Base Case
for i in range(n+1):
for j in range(amount+1):
if i==0:
... | coin-change-ii | EASIEST|| STEP-BY-STEP|| SIMPLE | Avinya | 0 | 40 | coin change ii | 518 | 0.599 | Medium | 9,132 |
https://leetcode.com/problems/coin-change-ii/discuss/1857215/Python-Recursion-%2B-Memoization | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
global k
l=len(coins)
k=[[-1 for i in range(amount+1)] for j in range(l+1)]
def trv(s,l,sum_s):
if sum_s==0:
return 1
if l==0 or sum_s<0:
return 0... | coin-change-ii | Python Recursion + Memoization | SahilSG2000 | 0 | 105 | coin change ii | 518 | 0.599 | Medium | 9,133 |
https://leetcode.com/problems/coin-change-ii/discuss/1853529/Python-Recursive-DP-solution-explained | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = {}
def helper(idx, amount):
# if you reach the amount, this
# is a valid path, return 1 (one way)
if amount == 0:
return 1
# if you're ou... | coin-change-ii | [Python] Recursive DP solution explained | buccatini | 0 | 112 | coin change ii | 518 | 0.599 | Medium | 9,134 |
https://leetcode.com/problems/coin-change-ii/discuss/1780668/Python-Easy-Solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp_arr = [1] + [0] * amount
print(dp_arr)
for coin in coins:
for idx in range(coin, amount+1):
dp_arr[idx] += dp_arr[idx - coin]
print(dp_arr)
return dp_arr[-1] | coin-change-ii | Python Easy Solution | ayush_kushwaha | 0 | 149 | coin change ii | 518 | 0.599 | Medium | 9,135 |
https://leetcode.com/problems/coin-change-ii/discuss/1775043/Python3-beats-99.25.-Fast-concise-and-simple | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
# one dimensional list to store the number of every possible combination for numbers from 0 to amount
arr = [0] * (amount+1)
#Base Case: If the total amount of money is zero, there is only one combination: to take zero coins.
... | coin-change-ii | Python3 beats 99.25%. Fast, concise, and simple | MaverickEyedea | 0 | 154 | coin change ii | 518 | 0.599 | Medium | 9,136 |
https://leetcode.com/problems/coin-change-ii/discuss/1767741/Java-Python3-Simple-DP-Solution-(Top-Down-and-Bottom-Up) | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
n = len(coins)
@lru_cache(None)
def dp(amount: int, coin_index: int) -> int:
# base case
if coin_index >= n or amount < 0:
return 0
if amount == 0:
ret... | coin-change-ii | ✅ [Java / Python3] Simple DP Solution (Top-Down & Bottom-Up) | JawadNoor | 0 | 102 | coin change ii | 518 | 0.599 | Medium | 9,137 |
https://leetcode.com/problems/coin-change-ii/discuss/1767741/Java-Python3-Simple-DP-Solution-(Top-Down-and-Bottom-Up) | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [0]*(amount+1)
dp[0] = 1
for coin in coins:
for i in range(coin, amount+1):
dp[i] += dp[i-coin]
return dp[amount] | coin-change-ii | ✅ [Java / Python3] Simple DP Solution (Top-Down & Bottom-Up) | JawadNoor | 0 | 102 | coin change ii | 518 | 0.599 | Medium | 9,138 |
https://leetcode.com/problems/coin-change-ii/discuss/1351986/Simple-DP-Solution-using-python | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp=[[0]*(amount+1) for row in range(len(coins))]
for row in range(len(coins)):
dp[row][0]=1
for col in range(1,amount+1):
if col%coins[0]==0:
dp[0][col]=1
for coin in range... | coin-change-ii | Simple DP Solution using python | karthik1117 | 0 | 137 | coin change ii | 518 | 0.599 | Medium | 9,139 |
https://leetcode.com/problems/coin-change-ii/discuss/1351462/Simple-and-Efficient-DP-solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
ways=[0]*(amount+1)
ways[0]=1
for coin in coins:
for amt in range(amount+1):
if coin<=amt:
ways[amt]=ways[amt]+ways[amt-coin]
return ways[-1]
Timp Comple... | coin-change-ii | Simple and Efficient DP solution | karthik1117 | 0 | 93 | coin change ii | 518 | 0.599 | Medium | 9,140 |
https://leetcode.com/problems/coin-change-ii/discuss/675184/Python3-dp-solution | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [0 for i in range(amount+1)]
dp[0] = 1
for i in coins:
for j in range(1, amount+1):
if i <= j:
dp[j] += dp[j-i]
return dp[amount] | coin-change-ii | Python3 dp solution | rajesh_26 | 0 | 188 | coin change ii | 518 | 0.599 | Medium | 9,141 |
https://leetcode.com/problems/coin-change-ii/discuss/647372/Simple-DP-Python-Solution | class Solution:
def change(self, val: int, d: List[int]) -> int:
if val!=0 and len(d)==0:
return 0
if val==0 or len(d)==0:
return 1
t=[]
for i in range(len(d)):
x=[]
for j in range(val+1):
x.append(0)
... | coin-change-ii | Simple DP Python Solution | Ayu-99 | 0 | 207 | coin change ii | 518 | 0.599 | Medium | 9,142 |
https://leetcode.com/problems/coin-change-ii/discuss/600115/PYTHON-3-DP-Solution-or-Bottom-Up-Approach | class Solution:
def change(self, amount: int, coins: List[int]) -> int:
dp = [[0] * (amount + 1) for i in range(len(coins) + 1)]
for i in range(len(coins) + 1):
for j in range(amount + 1):
if j == 0:
dp[i][j] = 1
elif i == 0:
... | coin-change-ii | [PYTHON 3] DP Solution | Bottom-Up Approach | mohamedimranps | 0 | 239 | coin change ii | 518 | 0.599 | Medium | 9,143 |
https://leetcode.com/problems/random-flip-matrix/discuss/2108517/Python3Three-solutions-with-detailed-explanation. | class Solution:
def __init__(self, m: int, n: int):
self.nums = m * n - 1
self.cols = n
self.flipped = set()
def flip(self) -> List[int]:
rc = random.randint(0, self.nums)
while rc in self.flipped:
rc = random.randint(0, self.nums)
... | random-flip-matrix | [Python3]Three solutions with detailed explanation. | AlainWong | 0 | 55 | random flip matrix | 519 | 0.399 | Medium | 9,144 |
https://leetcode.com/problems/random-flip-matrix/discuss/2108517/Python3Three-solutions-with-detailed-explanation. | class Solution:
def __init__(self, m: int, n: int):
self.cols = n
self.nums = m * n
self.tail = m * n - 1
self.indexes = [i for i in range(m * n)]
def flip(self) -> List[int]:
ind = random.randint(0, self.tail)
# swap the selected index with the index at se... | random-flip-matrix | [Python3]Three solutions with detailed explanation. | AlainWong | 0 | 55 | random flip matrix | 519 | 0.399 | Medium | 9,145 |
https://leetcode.com/problems/random-flip-matrix/discuss/2108517/Python3Three-solutions-with-detailed-explanation. | class Solution:
def __init__(self, m: int, n: int):
self.cols = n
self.nums = m * n
self.tail = self.nums - 1
self.indexes = {}
def flip(self) -> List[int]:
ind = random.randint(0, self.tail)
rc = self.indexes.get(ind, ind)
self.indexes... | random-flip-matrix | [Python3]Three solutions with detailed explanation. | AlainWong | 0 | 55 | random flip matrix | 519 | 0.399 | Medium | 9,146 |
https://leetcode.com/problems/detect-capital/discuss/336441/Solution-in-Python-3-(one-line) | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word in [word.upper(), word.lower(), word.title()]
- Python 3
- Junaid Mansuri | detect-capital | Solution in Python 3 (one line) | junaidmansuri | 6 | 541 | detect capital | 520 | 0.555 | Easy | 9,147 |
https://leetcode.com/problems/detect-capital/discuss/1715987/Python-Easy | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.isupper(): return True
if word.islower(): return True
if word[0].isupper() and word[1:].islower(): return True
return False | detect-capital | Python Easy | yashitanamdeo | 4 | 136 | detect capital | 520 | 0.555 | Easy | 9,148 |
https://leetcode.com/problems/detect-capital/discuss/1715105/Python-3-(20ms)-or-2-Solutions-or-Faster-than-95-or-One-Liner-or-Super-Easy-to-Understand | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word==word.lower() or word==word.upper() or word==(word[0].upper() + word[1:].lower()):
return True
return False | detect-capital | Python 3 (20ms) | 2 Solutions | Faster than 95% | One-Liner | Super Easy to Understand | MrShobhit | 3 | 50 | detect capital | 520 | 0.555 | Easy | 9,149 |
https://leetcode.com/problems/detect-capital/discuss/1715105/Python-3-(20ms)-or-2-Solutions-or-Faster-than-95-or-One-Liner-or-Super-Easy-to-Understand | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word.isupper() or word.islower() or word.istitle() | detect-capital | Python 3 (20ms) | 2 Solutions | Faster than 95% | One-Liner | Super Easy to Understand | MrShobhit | 3 | 50 | detect capital | 520 | 0.555 | Easy | 9,150 |
https://leetcode.com/problems/detect-capital/discuss/254040/Detect-Capital-Easy-code | `class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.isupper():
return True
elif word.islower():
return True
elif word.istitle():
return True
else:
return False` | detect-capital | Detect Capital Easy code | lalithbharadwaj | 2 | 97 | detect capital | 520 | 0.555 | Easy | 9,151 |
https://leetcode.com/problems/detect-capital/discuss/99254/Python-AC-solution-O(n) | class Solution(object):
def detectCapitalUse(self, word):
"""
:type word: str
:rtype: bool
"""
if word == word.upper() or word == word.lower():
return True
for letter in range(1,len(word)):
if word[letter] == word[letter].upper():
... | detect-capital | Python AC solution O(n) | lance5566 | 2 | 153 | detect capital | 520 | 0.555 | Easy | 9,152 |
https://leetcode.com/problems/detect-capital/discuss/1715442/Easy-O(n)-solution. | class Solution:
def detectCapitalUse(self, word: str) -> bool:
count = 0
for j in word:
if j.isupper():
count+=1
if (count == len(word)) or (count==1 and word[0].isupper()) or (not count):
return True
return False | detect-capital | Easy O(n) solution. | prashantpandey9 | 1 | 21 | detect capital | 520 | 0.555 | Easy | 9,153 |
https://leetcode.com/problems/detect-capital/discuss/1714512/daily-leetcode-challenge-easiest-approch | class Solution:
def detectCapitalUse(self, word: str) -> bool:
updn= word.upper()
if word == updn:
return True
updn = word.lower()
if word == updn:
return True
updn = word.capitalize()
if word == updn:
return True
else:
... | detect-capital | daily leetcode challenge easiest approch | apoorv11jain | 1 | 34 | detect capital | 520 | 0.555 | Easy | 9,154 |
https://leetcode.com/problems/detect-capital/discuss/1146329/Python3-simple-solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
x = word
if x.lower() == word:
return True
elif x.upper() == word:
return True
elif (x[1:].lower() == word[1:]) and (x[0].upper() == word[0]):
return True
else:
retu... | detect-capital | Python3 simple solution | EklavyaJoshi | 1 | 78 | detect capital | 520 | 0.555 | Easy | 9,155 |
https://leetcode.com/problems/detect-capital/discuss/2844897/python-3-liner | class Solution:
def detectCapitalUse(self, word: str) -> bool:
y =[x.isupper() for x in word]
if all(y)==True:
return True
z =[x.islower() for x in word]
if all(z)==True:
return True
if word[0].isupper()==True and all([x.islower() for x in word[1:]])==... | detect-capital | python 3 liner | sahityasetu1996 | 0 | 1 | detect capital | 520 | 0.555 | Easy | 9,156 |
https://leetcode.com/problems/detect-capital/discuss/2714215/using-isupper()-and-islower()-methods | class Solution:
def detectCapitalUse(self, word: str) -> bool:
for i in word:
if word[:].isupper():
return True
elif word[:].islower():
return True
elif word[0].isupper() and word[1:].islower():
return True
else:... | detect-capital | using isupper() and islower() methods | sindhu_300 | 0 | 7 | detect capital | 520 | 0.555 | Easy | 9,157 |
https://leetcode.com/problems/detect-capital/discuss/2701353/Python3-oror-99-oror-Easy-Understanding-oror-Simple-Solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if(word.upper() == word):
return True
if(word.lower() == word):
return True
if(word.capitalize() == word):
return True
return False | detect-capital | Python3 || 99% || Easy Understanding || Simple Solution | ahamedmusadiq_-12 | 0 | 6 | detect capital | 520 | 0.555 | Easy | 9,158 |
https://leetcode.com/problems/detect-capital/discuss/2682860/PYTHON-or-Beginner-or-Brute-force-or-Easy | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.islower() or word.isupper():
return True
else:
for i in range(len(word)):
if i==0 and word[i].isupper()==False:
return False
elif i!=0 and word[i].islowe... | detect-capital | PYTHON | Beginner | Brute-force | Easy | envyTheClouds | 0 | 6 | detect capital | 520 | 0.555 | Easy | 9,159 |
https://leetcode.com/problems/detect-capital/discuss/2661742/Python-one-liner | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word.isupper() or word.islower() or word.istitle() | detect-capital | Python one liner | thedtripp | 0 | 3 | detect capital | 520 | 0.555 | Easy | 9,160 |
https://leetcode.com/problems/detect-capital/discuss/2650504/Python-or-Easy-to-understand-or-using-Ord | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if ord(word[0]) >= 65 and ord(word[0]) <= 90:
startcap = True
else:
startcap = False
allcapital = True
for i in word[1:]:
if not (ord(i) >= 65 and ord(i) <= 90) :
... | detect-capital | Python | Easy to understand | using Ord | hk_davy | 0 | 2 | detect capital | 520 | 0.555 | Easy | 9,161 |
https://leetcode.com/problems/detect-capital/discuss/2623091/Python-faster-than-99.65 | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if len(word) == 1:
return True
sliced_list = word[1: len(word)]
if word[0].upper() and (word[1: len(word)].lower() == sliced_list):
return True
elif word == word.upper() or word == word.lower():
... | detect-capital | Python faster than 99.65% | Wielton | 0 | 20 | detect capital | 520 | 0.555 | Easy | 9,162 |
https://leetcode.com/problems/detect-capital/discuss/2617703/Simple-One-Line-or-Python | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word == word.upper() or word == word.lower() or word == word.capitalize() | detect-capital | Simple One Line | Python | Abhi_-_- | 0 | 10 | detect capital | 520 | 0.555 | Easy | 9,163 |
https://leetcode.com/problems/detect-capital/discuss/2526841/EXTREMELY-Clean-Simple-Python3-Code | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word == word.upper():
return True
elif word == word.lower():
return True
else:
if word[0] == word[0].upper() and word[1:] == word[1:].lower():
return True
else:
... | detect-capital | EXTREMELY Clean Simple Python3 Code | YuviGill | 0 | 20 | detect capital | 520 | 0.555 | Easy | 9,164 |
https://leetcode.com/problems/detect-capital/discuss/2467857/detailed-solution-using-loweruppertitle-in-py | class Solution:
def detectCapitalUse(self, w: str) -> bool:
if w==w.lower() or w==w.upper() or w==w.title():
return True
return False | detect-capital | detailed solution using lower,upper,title in py | tarak_ram_reddy | 0 | 13 | detect capital | 520 | 0.555 | Easy | 9,165 |
https://leetcode.com/problems/detect-capital/discuss/2391953/Easy-solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
l=len(word)
if l==1:
return True
if word[0]==word[0].lower() and word[1]==word[1].upper():
return False
u=False
if word[0]==word[0].upper():
if word[1]==word[1].upp... | detect-capital | Easy solution | sunakshi132 | 0 | 35 | detect capital | 520 | 0.555 | Easy | 9,166 |
https://leetcode.com/problems/detect-capital/discuss/2130138/Python-solution-easy-to-understand | class Solution:
def detectCapitalUse(self, word: str) -> bool:
for i in word:
if (word==word.upper() or word==(word[0].upper() + word[1:].lower()) or word==word.lower()):
return True
else:
return False | detect-capital | Python solution easy to understand | yashkumarjha | 0 | 50 | detect capital | 520 | 0.555 | Easy | 9,167 |
https://leetcode.com/problems/detect-capital/discuss/2013854/Python-oneliner | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word.isupper() or word.islower() or word.istitle() | detect-capital | Python oneliner | StikS32 | 0 | 66 | detect capital | 520 | 0.555 | Easy | 9,168 |
https://leetcode.com/problems/detect-capital/discuss/1979836/Easy-to-understand | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.isupper() or word.islower() or word.istitle():
return True
else:
return False | detect-capital | Easy to understand | user4774i | 0 | 16 | detect capital | 520 | 0.555 | Easy | 9,169 |
https://leetcode.com/problems/detect-capital/discuss/1928743/Python3-(One_line)-or-Runtime-99.21-faster | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word.isupper() or word.islower() or word.istitle() | detect-capital | Python3 (One_line) | Runtime 99.21% faster | jimmy605 | 0 | 20 | detect capital | 520 | 0.555 | Easy | 9,170 |
https://leetcode.com/problems/detect-capital/discuss/1919012/Python-one-liner-solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word.isupper() or word.islower() or word == word.capitalize() | detect-capital | Python one liner solution | alishak1999 | 0 | 22 | detect capital | 520 | 0.555 | Easy | 9,171 |
https://leetcode.com/problems/detect-capital/discuss/1863720/Python-Clean-and-Concise!-Multiple-Solutions! | class Solution:
def detectCapitalUse(self, word):
if len(word) < 2: return True
if word[0].islower():
for i in range(1, len(word)):
if word[i].isupper(): return False
else:
if word[1].isupper():
for i in range(2, len(word)):
... | detect-capital | Python - Clean and Concise! Multiple Solutions! | domthedeveloper | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,172 |
https://leetcode.com/problems/detect-capital/discuss/1863720/Python-Clean-and-Concise!-Multiple-Solutions! | class Solution:
def detectCapitalUse(self, word):
if len(word) < 2: return True
if word[0].isupper() and word[1].isupper():
for i in range(2, len(word)):
if word[i].islower(): return False
else:
for i in range(1, len(word)):
if... | detect-capital | Python - Clean and Concise! Multiple Solutions! | domthedeveloper | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,173 |
https://leetcode.com/problems/detect-capital/discuss/1863720/Python-Clean-and-Concise!-Multiple-Solutions! | class Solution:
def detectCapitalUse(self, word):
if str.isupper(word): return True
if str.islower(word): return True
if word[0].isupper() and str.islower(word[1:]): return True
return False | detect-capital | Python - Clean and Concise! Multiple Solutions! | domthedeveloper | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,174 |
https://leetcode.com/problems/detect-capital/discuss/1863720/Python-Clean-and-Concise!-Multiple-Solutions! | class Solution:
def detectCapitalUse(self, word):
return word.isupper() or word.islower() or (word[0].isupper() and word[1:].islower()) | detect-capital | Python - Clean and Concise! Multiple Solutions! | domthedeveloper | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,175 |
https://leetcode.com/problems/detect-capital/discuss/1863720/Python-Clean-and-Concise!-Multiple-Solutions! | class Solution:
def detectCapitalUse(self, word):
return word.isupper() or word.islower() or word.istitle() | detect-capital | Python - Clean and Concise! Multiple Solutions! | domthedeveloper | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,176 |
https://leetcode.com/problems/detect-capital/discuss/1787922/Fast-and-Simple-Code | class Solution:
def detectCapitalUse(self, word: str) -> bool:
a='QWERTYUIOPLKJHGFDSAZXCVBNM'
if word.islower() or word.isupper():
return True
if word[0] not in a:
return False
s=word[1:]
if s.islower() or s.isupper():
return True
r... | detect-capital | Fast and Simple Code | adityabaner | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,177 |
https://leetcode.com/problems/detect-capital/discuss/1738246/Python-sets-and-ascii_uppercase-ascii_lowercase | class Solution:
def detectCapitalUse(self, word: str) -> bool:
uppercase_set = set(string.ascii_uppercase)
lowercase_set = set(string.ascii_lowercase)
word_set = set(word)
new_set = word_set - uppercase_set
len_new_set = len(new_set)
if not len_new_set or len_new_set == len(word_set):
re... | detect-capital | Python sets and ascii_uppercase, ascii_lowercase | manulik | 0 | 36 | detect capital | 520 | 0.555 | Easy | 9,178 |
https://leetcode.com/problems/detect-capital/discuss/1732224/Python3-One-pass-solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
cnt = 0
for char in word:
if char.isupper():
cnt += 1
return cnt == len(word) or (cnt == 1 and word[0].isupper()) or cnt == 0 | detect-capital | [Python3] One pass solution | maosipov11 | 0 | 18 | detect capital | 520 | 0.555 | Easy | 9,179 |
https://leetcode.com/problems/detect-capital/discuss/1721304/Python-Two-Solutions-easy-to-understand | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if len(word)<=1:
return True
if ord(word[0]) - ord('a')<0:
d=1
else:
d=0
if d==0:
for i in range(1,len(word)):
if ord(word[i]) - ord('a') <0:
return False
else:
if ord(word[1]) - ord('a')>=0:
for i in range(2,len(word... | detect-capital | Python Two Solutions easy to understand | vermaayush680 | 0 | 15 | detect capital | 520 | 0.555 | Easy | 9,180 |
https://leetcode.com/problems/detect-capital/discuss/1721304/Python-Two-Solutions-easy-to-understand | class Solution:
def detectCapitalUse(self, word: str) -> bool:
d="A"<=word[0]<="Z"
c=0
for i in word:
c+=("A"<=i<="Z")
if c==len(word) or c==0 or (c==1 and d==1):
return True
else:
return False | detect-capital | Python Two Solutions easy to understand | vermaayush680 | 0 | 15 | detect capital | 520 | 0.555 | Easy | 9,181 |
https://leetcode.com/problems/detect-capital/discuss/1716350/Simple-and-fast-solution-beats-97 | class Solution:
def detectCapitalUse(self, word: str) -> bool:
min_value, max_value = ord('A'), ord('Z')
total_up_symbols = 0
for symbol in word:
if min_value <= ord(symbol) <= max_value:
total_up_symbols += 1
if total_up_symbols == len(word):
... | detect-capital | Simple and fast solution beats 97% | Fyzzys | 0 | 14 | detect capital | 520 | 0.555 | Easy | 9,182 |
https://leetcode.com/problems/detect-capital/discuss/1716118/Python-Most-simplest-solution-you-have-ever-seen-of-this-problem | class Solution:
def detectCapitalUse(self, word: str) -> bool:
#1st case:- when All letters are capital
if(word.isupper()):
return True
#2nd case:- When only first letter is capital
elif(word.istitle()):
return True
#3rd case:- When all letters are in lowercase
e... | detect-capital | [Python] Most simplest solution you have ever seen of this problem | nitishkumarthakur125 | 0 | 9 | detect capital | 520 | 0.555 | Easy | 9,183 |
https://leetcode.com/problems/detect-capital/discuss/1715607/Python-Easy-linear-search | class Solution:
def detectCapitalUse(self, word: str) -> bool:
cap = []
for idx,i in enumerate(word):
if i.upper() == i:
cap.append(idx)
if len(cap) == len(word) or (len(cap)==1 and cap[0]==0) or len(cap)==0:
return True
return False | detect-capital | Python - Easy linear search | hrithikhh86 | 0 | 14 | detect capital | 520 | 0.555 | Easy | 9,184 |
https://leetcode.com/problems/detect-capital/discuss/1715582/fast-greater91.10-memorygreater91.67-python3-solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if re.fullmatch('[A-Z]*', word):
return True
if re.fullmatch('.[a-z]*', word):
return True
return False | detect-capital | fast >91.10% memory>91.67% python3 solution | fatmakahveci | 0 | 16 | detect capital | 520 | 0.555 | Easy | 9,185 |
https://leetcode.com/problems/detect-capital/discuss/1715495/Easy-Python-Solution-! | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.isupper()==True:
return True
elif word.islower()==True:
return True
elif word[0].isupper()==True and word[1:].islower()==True:
return True
else:
return False | detect-capital | Easy Python Solution ! ✔✔ | ASHOK_KUMAR_MEGHVANSHI | 0 | 17 | detect capital | 520 | 0.555 | Easy | 9,186 |
https://leetcode.com/problems/detect-capital/discuss/1715380/Python3-Easy-solution-with-Explanation | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if len(word) == 1:
return True
elif word[0].isupper() == True:
# either check for all capitals or check for all small
if word[1:].isupper() == False and word[1:].islower() == False:
ret... | detect-capital | Python3 - Easy solution with Explanation | rishabhmanu | 0 | 8 | detect capital | 520 | 0.555 | Easy | 9,187 |
https://leetcode.com/problems/detect-capital/discuss/1714681/Python-3-EASY-Intuitive-Solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.islower() or word.isupper() or word.istitle():
return True
return False | detect-capital | ✅ [Python 3] EASY Intuitive Solution | JawadNoor | 0 | 13 | detect capital | 520 | 0.555 | Easy | 9,188 |
https://leetcode.com/problems/detect-capital/discuss/1714601/Python3-Just-a-Simple-One-Pass-Solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
n = 0
for i, c in enumerate(word):
if c == c.upper():
n += 1
# If the first capital letter is not found at the first index, return False since we are violating Condition 3
if n == 1 and i !... | detect-capital | ✅ [Python3] Just a Simple One Pass Solution | PatrickOweijane | 0 | 18 | detect capital | 520 | 0.555 | Easy | 9,189 |
https://leetcode.com/problems/detect-capital/discuss/1714601/Python3-Just-a-Simple-One-Pass-Solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
n = 0
for i, c in enumerate(word):
if c == c.upper():
n += 1
if n == 1 and i != 0: return False
return n <= 1 or n == len(word) | detect-capital | ✅ [Python3] Just a Simple One Pass Solution | PatrickOweijane | 0 | 18 | detect capital | 520 | 0.555 | Easy | 9,190 |
https://leetcode.com/problems/detect-capital/discuss/1714523/Python-Solution | class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.upper() == word:
return True
elif word.lower() == word:
return True
elif word.capitalize() == word:
return True
else:
return False | detect-capital | Python Solution | pradeep288 | 0 | 31 | detect capital | 520 | 0.555 | Easy | 9,191 |
https://leetcode.com/problems/detect-capital/discuss/1714500/Python-3-Solution-Linear-Detailed-Explanation | class Solution:
def detectCapitalUse(self, word: str) -> bool:
def isSameCase(l, r, word, isUpper):
while l <= r:
if word[l].isupper() != isUpper or word[r].isupper() != isUpper:
return False
l += 1
r -= 1
return Tru... | detect-capital | [Python 3] Solution Linear Detailed Explanation | gcobs0834 | 0 | 10 | detect capital | 520 | 0.555 | Easy | 9,192 |
https://leetcode.com/problems/detect-capital/discuss/1445721/Python-oror-Easy-Solution-oror-beat~100 | class Solution:
def detectCapitalUse(self, s: str) -> bool:
return s.isupper() or s.islower() or (s[0].isupper() and s[1:].islower()) | detect-capital | Python || Easy Solution || beat~100% | naveenrathore | 0 | 81 | detect capital | 520 | 0.555 | Easy | 9,193 |
https://leetcode.com/problems/longest-uncommon-subsequence-i/discuss/1277607/python-two-lines-or-easy | class Solution:
def findLUSlength(self, a: str, b: str) -> int:
if a==b:return -1
else:return max(len(a),len(b)) | longest-uncommon-subsequence-i | python two lines | easy | chikushen99 | 4 | 314 | longest uncommon subsequence i | 521 | 0.603 | Easy | 9,194 |
https://leetcode.com/problems/longest-uncommon-subsequence-i/discuss/1107814/Python3-simple-one-liner-solution | class Solution:
def findLUSlength(self, a: str, b: str) -> int:
return -1 if a == b else max(len(a), len(b)) | longest-uncommon-subsequence-i | Python3 simple one-liner solution | EklavyaJoshi | 4 | 302 | longest uncommon subsequence i | 521 | 0.603 | Easy | 9,195 |
https://leetcode.com/problems/longest-uncommon-subsequence-i/discuss/380325/Solution-in-Python-3-(beats-~90)-(one-line) | class Solution:
def findLUSlength(self, a: str, b: str) -> int:
return -1 if a == b else max(len(a),len(b))
- Junaid Mansuri
(LeetCode ID)@hotmail.com | longest-uncommon-subsequence-i | Solution in Python 3 (beats ~90%) (one line) | junaidmansuri | 4 | 650 | longest uncommon subsequence i | 521 | 0.603 | Easy | 9,196 |
https://leetcode.com/problems/longest-uncommon-subsequence-i/discuss/1014958/Simple-and-easy-faster-than-98.9 | class Solution:
def findLUSlength(self, a: str, b: str) -> int:
if a==b:
return -1
l=[a[i:] for i in range(len(a))] #We make a list containing all the substrings of given string a and then compare
for i in l:
if i!=b:
return len(i) if len(i)>len(b) els... | longest-uncommon-subsequence-i | Simple and easy- faster than 98.9% | thisisakshat | 3 | 209 | longest uncommon subsequence i | 521 | 0.603 | Easy | 9,197 |
https://leetcode.com/problems/longest-uncommon-subsequence-i/discuss/2769117/Python3ororO(1) | class Solution:
def findLUSlength(self, A: str, B: str) -> int:
if A == B:
return -1
return max(len(A), len(B)) | longest-uncommon-subsequence-i | Python3||O(1) | Sneh713 | 1 | 50 | longest uncommon subsequence i | 521 | 0.603 | Easy | 9,198 |
https://leetcode.com/problems/longest-uncommon-subsequence-i/discuss/1918796/Python-solution-faster-than-84 | class Solution:
def findLUSlength(self, a: str, b: str) -> int:
if a == b:
return -1
if len(a) > len(b):
return len(a)
return len(b) | longest-uncommon-subsequence-i | Python solution faster than 84% | alishak1999 | 1 | 133 | longest uncommon subsequence i | 521 | 0.603 | Easy | 9,199 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.