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/maximum-bags-with-full-capacity-of-rocks/discuss/2215447/Python-simple-solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
empty = sorted([c-r for c,r in zip(capacity, rocks)])
ans = 0
for i in empty:
if i == 0:
ans += 1
elif i <= additionalRocks:
addi... | maximum-bags-with-full-capacity-of-rocks | Python simple solution | StikS32 | 0 | 5 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,500 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2135384/Python-oror-Straight-Forward | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
n, tofill = len(capacity), defaultdict(int)
for i in range(n):
tofill[i] = capacity[i] - rocks[i]
k, v = tofill.keys(), tofill.values()
bags, i, filled = sorted(v), 0, 0
while additionalRocks and ... | maximum-bags-with-full-capacity-of-rocks | Python || Straight Forward | morpheusdurden | 0 | 16 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,501 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2116182/Python-Easy-to-understand-Solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
n = len(capacity)
minus_list = []
for i in range(n):
minus_list.append(capacity[i] - rocks[i])
minus_list.sort()
add_rocks = 0
ans = 0
whi... | maximum-bags-with-full-capacity-of-rocks | ✅Python Easy-to-understand Solution | chuhonghao01 | 0 | 13 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,502 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2071568/python-3-oror-simple-greedy-solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
n = len(capacity)
for i in range(n):
capacity[i] -= rocks[i]
capacity.sort()
for i, additonalCapacity in enumerate(capacity):
additiona... | maximum-bags-with-full-capacity-of-rocks | python 3 || simple greedy solution | dereky4 | 0 | 36 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,503 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2068291/Python3-greedy | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
ans = 0
for x in sorted(c - r for c, r in zip(capacity, rocks)):
if x <= additionalRocks:
ans += 1
additionalRocks -= x
return ans | maximum-bags-with-full-capacity-of-rocks | [Python3] greedy | ye15 | 0 | 21 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,504 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2066020/java-python-small-and-fast-(sorting) | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
for i in range(len(capacity)):
capacity[i] -= rocks[i]
capacity.sort()
for i in range(len(capacity)):
if capacity[i] > additionalRocks : return i
additionalRocks -= capacity[i... | maximum-bags-with-full-capacity-of-rocks | java, python - small & fast (sorting) | ZX007java | 0 | 15 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,505 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2061929/Very-simple-and-easy-to-understand-Heap-Solution%3A-Python | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
heap = []
answer = 0
n = len(rocks)
for i in range(n):
heappush(heap, (
capacity[i] - rocks[i],
i
))
while heap... | maximum-bags-with-full-capacity-of-rocks | Very simple and easy to understand Heap Solution: Python | tyrocoder | 0 | 15 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,506 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2061893/Python-or-Easy-to-Understand | class Solution:
def minimumLines(self, stockPrices: List[List[int]]) -> int:
# key point: never use devision to judge whether 3 points are on a same line or not, use the multiplication instead !!
n = len(stockPrices)
stockPrices.sort(key = lambda x: (x[0], x[1]))
if... | minimum-lines-to-represent-a-line-chart | Python | Easy to Understand | Mikey98 | 11 | 548 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,507 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2061827/PYTHON-SIMPLE-SOLUTION-or-EASY-TO-UNDERSTAND-LOGIC-or-SORTING | class Solution:
def minimumLines(self, stockPrices: List[List[int]]) -> int:
if len(stockPrices) == 1:
return 0
stockPrices.sort(key = lambda x: x[0])
ans = 1
for i in range(1,len(stockPrices)-1):
if (stockPrices[i+1][1]-stockPrices[i][1])*(stockPrices[i][0]-s... | minimum-lines-to-represent-a-line-chart | PYTHON SIMPLE SOLUTION | EASY TO UNDERSTAND LOGIC | SORTING | AkashHooda | 2 | 74 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,508 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2097954/PYTHON-oror-EXPLAINED-oror-EASY | class Solution:
def minimumLines(self, a: List[List[int]]) -> int:
if len(a)<=1:
return 0
a.sort()
ans=1
for i in range(2,len(a)):
if ((a[i-1][1]-a[i-2][1])*(a[i][0]-a[i-1][0]))!=((a[i][1]-a[i-1][1])*(a[i-1][0]-a[i-2][0])):
ans+=1
... | minimum-lines-to-represent-a-line-chart | ✔️PYTHON || ✔️EXPLAINED || EASY | karan_8082 | 1 | 76 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,509 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2572896/Concise-Python-Implementation-with-GCD | class Solution:
def gcd(self, a, b):
while b != 0:
a, b = b, a % b
return a
def compute_slope(self, p1, p2):
slope_x, slope_y = p2[0] - p1[0], p2[1] - p1[1]
g = self.gcd(slope_x, slope_y)
return (slope_x // g, slope_y // g)
def minimumLines(s... | minimum-lines-to-represent-a-line-chart | Concise Python Implementation with GCD | metaphysicalist | 0 | 27 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,510 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2135385/Python-oror-Straight-Forward | class Solution:
def minimumLines(self, stockPrices: List[List[int]]) -> int:
n = len(stockPrices)
if n == 2: return 1
if n == 1: return 0
day, price = [],[]
for d, p in stockPrices:
day.append(d)
price.append(p)
stocks = sorted(zip(day,price))
line = 1
for i in range(1,n-1):
p1, p2, p3 = stoc... | minimum-lines-to-represent-a-line-chart | Python || Straight Forward | morpheusdurden | 0 | 74 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,511 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2116173/Python-Easy-to-understand-Solution | class Solution:
def minimumLines(self, stockPrices: List[List[int]]) -> int:
stockPrices.sort()
n = len(stockPrices)
ans = 1
i = 0
if n < 2:
return 0
if len(stockPrices) == 0:
return 0
while i + 2 < n:
whi... | minimum-lines-to-represent-a-line-chart | ✅Python Easy-to-understand Solution | chuhonghao01 | 0 | 30 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,512 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2068296/Python3-piece-by-piece | class Solution:
def minimumLines(self, stockPrices: List[List[int]]) -> int:
stockPrices.sort()
ans = 0
for i in range(1, len(stockPrices)):
if i == 1 or (stockPrices[i][1]-stockPrices[i-1][1])*(stockPrices[i-1][0]-stockPrices[i-2][0]) != (stockPrices[i-1][1]-stockPrices[i-2][1]... | minimum-lines-to-represent-a-line-chart | [Python3] piece by piece | ye15 | 0 | 17 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,513 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2066085/python-java-c%2B%2B-easy-and-small-(commented) | class Solution:
def minimumLines(self, s: List[List[int]]) -> int:
if len(s) == 1 : return 0
s.sort()
ans = 1
for i in range(2,len(s)) :
if (s[i][0] - s[i-1][0])*(s[i-2][1] - s[i-1][1]) != (s[i][1] - s[i-1][1])*(s[i-2][0] - s[i-1][0]): ans+=1
return ans | minimum-lines-to-represent-a-line-chart | python, java, c++ - easy & small (commented) | ZX007java | 0 | 20 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,514 |
https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/discuss/2062112/Easy-python-code-using-slope | class Solution:
def minimumLines(self, stockPrices: List[List[int]]) -> int:
if len(stockPrices) == 1 :
return 0
if len(stockPrices) == 2:
return 1
number = 1
stockPrices.sort()
for i in range(2, len(stockPrices)):
if int((stockPrices[i][1]... | minimum-lines-to-represent-a-line-chart | Easy python code using slope | mdai26 | 0 | 26 | minimum lines to represent a line chart | 2,280 | 0.238 | Medium | 31,515 |
https://leetcode.com/problems/sum-of-total-strength-of-wizards/discuss/2373525/faster-than-98.90-or-easy-python-or-solution | class Solution:
def totalStrength(self, strength: List[int]) -> int:
strength = [0] + strength + [0]
def calc_prefix_sum(array):
if not array: return []
result = [array[0]]
for el in array[1:]:
result.append(array[-1]+el)
return result
... | sum-of-total-strength-of-wizards | faster than 98.90% | easy python | solution | vimla_kushwaha | 2 | 1,800 | sum of total strength of wizards | 2,281 | 0.279 | Hard | 31,516 |
https://leetcode.com/problems/sum-of-total-strength-of-wizards/discuss/2068305/Python3-mono-stack | class Solution:
def totalStrength(self, strength: List[int]) -> int:
ans = 0
stack = []
prefix = list(accumulate(accumulate(strength), initial=0))
for i, x in enumerate(strength + [0]):
while stack and stack[-1][1] >= x:
mid = stack.pop()[0]
... | sum-of-total-strength-of-wizards | [Python3] mono-stack | ye15 | 1 | 258 | sum of total strength of wizards | 2,281 | 0.279 | Hard | 31,517 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084112/Python-Easy-solution | class Solution:
def digitCount(self, num: str) -> bool:
counter=Counter(num)
for i in range(len(num)):
if counter[f'{i}'] != int(num[i]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python Easy solution | constantine786 | 3 | 142 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,518 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084641/Python-or-Easy-and-understanding-solution | class Solution:
def digitCount(self, num: str) -> bool:
n=len(num)
for i in range(n):
if(num.count(str(i))!=int(num[i])):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python | Easy & understanding solution | backpropagator | 2 | 116 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,519 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2710543/Easty-Python | class Solution:
def digitCount(self, s: str) -> bool:
for i in range(len(s)):
c=s.count(str(i))
if c==int(s[i]):
continue
else:
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | [Easty Python ] | Sneh713 | 1 | 97 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,520 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084315/Clean-Python-Code-using-Counter | class Solution:
def digitCount(self, num: str) -> bool:
d = Counter(num)
for idx, val in enumerate(num):
if int(val) != d[str(idx)]:
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Clean Python Code using Counter | yzhao156 | 1 | 23 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,521 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2083886/Solution-using-hash-map-in-Python | class Solution:
def digitCount(self, num: str) -> bool:
leng = len(num)
freq = {}
for i in range(leng):
freq[str(i)] = 0
for i in range(leng):
if num[i] in freq:
freq[num[i]] += 1
for i in range(leng):
... | check-if-number-has-equal-digit-count-and-digit-value | Solution using hash map in Python | ReBirthing | 1 | 73 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,522 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2752706/Python-one-line-without-count | class Solution:
def digitCount(self, num: str) -> bool:
return num in {'1210','21200','2020'} or num == str(len(num)-4) + '21' + '0' * (len(num)-7) + '1000' | check-if-number-has-equal-digit-count-and-digit-value | Python one line without count | Fredrick_LI | 0 | 3 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,523 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2735627/Pyhton-or-Easy-Solution | class Solution:
def digitCount(self, num: str) -> bool:
num = [int(i) for i in num]
for i in range(len(num)):
if int(list(num).count(i)) != int(num[i]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Pyhton | Easy Solution | atharva77 | 0 | 1 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,524 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2583434/hashmap | class Solution:
def digitCount(self, num: str) -> bool:
# the index is the key
# the element at the index dictates the freq
# iterate over nums storing occurences of nums in d
# iterate nums asserting that the values match
# time O(n^2) space O(1)
d = dict()
... | check-if-number-has-equal-digit-count-and-digit-value | hashmap | andrewnerdimo | 0 | 27 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,525 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2499371/Python3-Straightforward-One-liner | class Solution:
def digitCount(self, num: str) -> bool:
return all(num.count(str(i)) == int(num[i]) for i in range(len(num))) | check-if-number-has-equal-digit-count-and-digit-value | [Python3] Straightforward One-liner | ivnvalex | 0 | 20 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,526 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2342188/Python-simple-and-fast-solution | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(0, len(num)):
if num[i] != str(num.count(str(i))):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python - simple and fast solution | kennytruong001 | 0 | 40 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,527 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2314996/Python3-freq-table | class Solution:
def digitCount(self, num: str) -> bool:
freq = Counter(map(int, str(num)))
return all(freq[i] == int(ch) for i, ch in enumerate(str(num))) | check-if-number-has-equal-digit-count-and-digit-value | [Python3] freq table | ye15 | 0 | 18 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,528 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2296508/EASY-PYTHON-SOLUTION-oror-using-dictionary-oror | class Solution:
def digitCount(self, num: str) -> bool:
dic = {}
for i in range(len(num)) :
if num[i] in dic :
dic[num[i]] += 1
else :
dic[num[i]] = 0
if str(i) in dic :
dic[str(i)] += 1
else :
... | check-if-number-has-equal-digit-count-and-digit-value | EASY PYTHON SOLUTION || using dictionary || | rohitkhairnar | 0 | 19 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,529 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2296508/EASY-PYTHON-SOLUTION-oror-using-dictionary-oror | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(len(num)):
if(num.count(str(i))!=int(num[i])): return False
return True | check-if-number-has-equal-digit-count-and-digit-value | EASY PYTHON SOLUTION || using dictionary || | rohitkhairnar | 0 | 19 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,530 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2208669/python-1-Liner-using-Counter | class Solution:
def digitCount(self, num: str) -> bool:
return all([Counter(num)[str(i)]==int(num[i]) for i in range(len(num))]) | check-if-number-has-equal-digit-count-and-digit-value | python 1-Liner using Counter | XRFXRF | 0 | 33 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,531 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2131537/Python-oror-Easy-Solution | class Solution:
def digitCount(self, nums: str) -> bool:
n = len(nums)
count = defaultdict(int)
for dig in nums:
count[dig] += 1
for i in range(n):
if count[str(i)] != int(nums[i]): return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python || Easy Solution | morpheusdurden | 0 | 50 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,532 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2119335/Python3-easy-solution | class Solution:
def digitCount(self, num: str) -> bool:
new = Counter(num)
for i in range(len(num)):
if str(num[i]) != str(new[str(i)]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python3 easy solution | yashkumarjha | 0 | 46 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,533 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2116157/Python-Easy-to-understand-Solution | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(len(num)):
s = str(i)
if num.count(s) != int(num[i]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | ✅Python Easy-to-understand Solution | chuhonghao01 | 0 | 20 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,534 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2109034/Python-3-Easy-Python-solution-for-Beginners | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(len(num)):
if num.count(str(i))!=int(num[i]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | [Python 3] Easy Python solution for Beginners | kushal2201 | 0 | 34 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,535 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2099803/Python-simple-solution | class Solution:
def digitCount(self, num: str) -> bool:
for ind, i in enumerate(num):
if num.count(str(ind)) != int(i):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python simple solution | StikS32 | 0 | 27 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,536 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2094846/Python-easy-solution-for-beginners | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(len(num)):
if str(num.count(str(i))) != num[i]:
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python easy solution for beginners | alishak1999 | 0 | 22 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,537 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2094363/Python-Detailed-Solution | class Solution:
def digitCount(self, num: str) -> bool:
m = {}
for digit in num:
if digit in m:
m[digit] += 1
else:
m[digit] = 1
for i in range(len(num)):
x = int(num[i])
if str(i) not in m:
... | check-if-number-has-equal-digit-count-and-digit-value | Python Detailed Solution | Hejita | 0 | 20 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,538 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2088328/java-paython-easy-ASCII-solution | class Solution:
def digitCount(self, num: str) -> bool:
digits = [0]*10
for letter in num : digits[ord(letter) - 48] += 1
for i in range(len(num)) :
idx = ord(num[i]) - 48
if digits[i] != idx : return False
return True | check-if-number-has-equal-digit-count-and-digit-value | java, paython - easy ASCII solution | ZX007java | 0 | 16 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,539 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084493/Python-2-lines-or-Counter-or-100-faster | class Solution:
def digitCount(self, num: str) -> bool:
# create counter map & compare
hm = Counter(map(int,num))
return all(int(num[i]) == hm.get(i,0) for i in range(len(num))) | check-if-number-has-equal-digit-count-and-digit-value | Python 2 lines | Counter | 100% faster | Nk0311 | 0 | 19 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,540 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084418/Python3-Simple-Solution | class Solution:
def digitCount(self, num: str) -> bool:
d = {}
for i in num:
n = int(i)
d[n] = d.get(n,0) + 1
for i in range(len(num)):
n = d.get(i,0)
if n != int(num[i]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Python3 Simple Solution | abhijeetmallick29 | 0 | 14 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,541 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084363/Python-using-Counter | class Solution:
def digitCount(self, num: str) -> bool:
num = list(map(int, num))
c = Counter(num)
return all(c[i] == d for i, d in enumerate(num)) | check-if-number-has-equal-digit-count-and-digit-value | Python, using Counter | blue_sky5 | 0 | 28 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,542 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084301/Easy-Understanding-python-solution | class Solution:
def digitCount(self, num: str) -> bool:
flag = 0
for i in range(len(num)):
if num.count(str(i)) == int(num[i]):
flag=1
else:
return False
if flag == 1:
return True | check-if-number-has-equal-digit-count-and-digit-value | Easy Understanding python solution | srija100 | 0 | 13 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,543 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084207/Easy-Python-solution | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(len(num)):
if int(num.count(str(i)))!=int(num[i]):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | Easy Python solution | a_dityamishra | 0 | 11 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,544 |
https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/discuss/2084178/Python-3-Easy-Solution | class Solution:
def digitCount(self, num: str) -> bool:
for i in range(len(num)):
if int(num[i]) != num.count(str(i)):
return False
return True | check-if-number-has-equal-digit-count-and-digit-value | [Python 3] - Easy Solution | hari19041 | 0 | 25 | check if number has equal digit count and digit value | 2,283 | 0.735 | Easy | 31,545 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084222/Easy-Python-Solution-With-Dictionary | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d={}
l=[]
for i in range(len(messages)):
if senders[i] not in d:
d[senders[i]]=len(messages[i].split())
else:
d[senders[i]]+=len(messages[i].spl... | sender-with-largest-word-count | Easy Python Solution With Dictionary | a_dityamishra | 7 | 356 | sender with largest word count | 2,284 | 0.561 | Medium | 31,546 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2643277/Python3-or-Hash-word-count-associated-with-a-sender's-name-then-return-max | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
words_count = defaultdict(int)
for m, person in zip(messages, senders):
words_count[person] += len(m.split())
max_len = max(words_count.values())
names = ... | sender-with-largest-word-count | Python3 | Hash word count associated with a sender's name then return max | Ploypaphat | 1 | 43 | sender with largest word count | 2,284 | 0.561 | Medium | 31,547 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2151937/Python3-Clear-solution-using-dictionaries-for-word-count-per-sender | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
word_count = {}
for message, sender in zip(messages, senders):
message_word_count = message.count(" ") + 1
word_count[sender] = word_count.get(sender, 0) + message_word_count
... | sender-with-largest-word-count | Python3 - Clear solution using dictionaries for word count per sender | ahmadheshamzaki | 1 | 67 | sender with largest word count | 2,284 | 0.561 | Medium | 31,548 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084386/Python-Solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d = defaultdict(list)
for m, s in zip(messages, senders):
d[s].append(m)
longest = [0, []]
for s in d:
l = 0
for m in d[s]:
l += l... | sender-with-largest-word-count | Python Solution | user6397p | 1 | 26 | sender with largest word count | 2,284 | 0.561 | Medium | 31,549 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084321/Python3-or-5-Lines-or-Easy-understanding | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d = defaultdict(int)
for sender, size in zip( senders, [len(message.split()) for message in messages] ):
d[sender] += size
max_word = max(d.values())
return sorted([sender for send... | sender-with-largest-word-count | Python3 | 5 Lines | Easy understanding | yzhao156 | 1 | 22 | sender with largest word count | 2,284 | 0.561 | Medium | 31,550 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2083973/Solution-in-Python-or-Hashmap-or-Sorting | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
leng = len(senders)
freq = {}
for i in range(leng):
sender = senders[i]
msg = messages[i]
msg_len = len(msg.split())
if sender in freq:
... | sender-with-largest-word-count | Solution in Python | Hashmap | Sorting | ReBirthing | 1 | 60 | sender with largest word count | 2,284 | 0.561 | Medium | 31,551 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2083912/Python-Easy-Solution-using-Hashing-and-Sorting | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
mapping, res = {}, []
for i, sender in enumerate(senders):
if sender not in mapping:
mapping[sender] = len(messages[i].split())
else:
mapping[s... | sender-with-largest-word-count | Python Easy Solution using Hashing and Sorting | MiKueen | 1 | 43 | sender with largest word count | 2,284 | 0.561 | Medium | 31,552 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2083877/Python-Easy-Approach | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
counter = defaultdict(int)
max_count = -math.inf
res=''
# find the word count tally for each sender
for message, sender in zip(messages, senders):
counter[sende... | sender-with-largest-word-count | Python Easy Approach | constantine786 | 1 | 56 | sender with largest word count | 2,284 | 0.561 | Medium | 31,553 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2830991/Python-hashmap-solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d = {}
for i in range(len(senders)):
if senders[i] in d.keys():
d[senders[i]] += len(messages[i].split())
else:
d[senders[i]] = len(messages[i].split())... | sender-with-largest-word-count | Python hashmap solution | AdvaitShukla | 0 | 1 | sender with largest word count | 2,284 | 0.561 | Medium | 31,554 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2827234/Simple-Solution-using-Dictionary-in-Python | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
map = {}
m=0
ans=""
for i in range(len(senders)):
if senders[i] not in map:
map[senders[i]] = messages[i].count(' ')+1
else:
map[sender... | sender-with-largest-word-count | Simple Solution using Dictionary in Python | niketh_1234 | 0 | 1 | sender with largest word count | 2,284 | 0.561 | Medium | 31,555 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2812586/Simple-Python-Solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
count = collections.defaultdict(int)
for i in range(len(senders)):
count[senders[i]] += len(messages[i].split())
ans = []
for k, v in count.items():
if ans == [] or v >... | sender-with-largest-word-count | Simple Python Solution | akki2790 | 0 | 1 | sender with largest word count | 2,284 | 0.561 | Medium | 31,556 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2740029/Python3-Solution-with-using-hashmap | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d = collections.defaultdict(int)
for idx, sender in enumerate(senders):
space_cnt = 0
for char in messages[idx]:
if char == " ":
space_cnt ... | sender-with-largest-word-count | [Python3] Solution with using hashmap | maosipov11 | 0 | 3 | sender with largest word count | 2,284 | 0.561 | Medium | 31,557 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2723526/Python-solution-beats-100-on-time-(340ms)-and-94.42-on-space-(21.2-MB) | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
a = {}
for message, sender in zip(messages, senders):
words = message.count(' ') + 1
if sender not in a:
a[sender] = words
else:
a[sender]... | sender-with-largest-word-count | Python solution beats 100% on time (340ms) and 94.42% on space (21.2 MB) | dmonack | 0 | 3 | sender with largest word count | 2,284 | 0.561 | Medium | 31,558 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2721547/PYTHON-Faster-than-99.82-oror-Easy-python-solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
hashmap = dict()
for message, name in zip(messages, senders):
if name in hashmap:
hashmap[name] += len(message.split(" "))
else:
hashmap[name] ... | sender-with-largest-word-count | [PYTHON] Faster than 99.82% || Easy python solution | valera_grishko | 0 | 5 | sender with largest word count | 2,284 | 0.561 | Medium | 31,559 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2690573/Python-or-7-lines-or-Dictionary | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
counts = Counter()
for mess, sender in zip(messages, senders):
counts[sender] += mess.count(' ') + 1
ans = (float('-inf'), "")
for sender, count in counts.items():
an... | sender-with-largest-word-count | Python | 7 lines | Dictionary | on_danse_encore_on_rit_encore | 0 | 4 | sender with largest word count | 2,284 | 0.561 | Medium | 31,560 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2547219/easy-python-solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
sender_dict = {}
for i in range(len(senders)) :
if senders[i] not in sender_dict.keys() :
sender_dict[senders[i]] = len(messages[i].split())
else :
s... | sender-with-largest-word-count | easy python solution | sghorai | 0 | 22 | sender with largest word count | 2,284 | 0.561 | Medium | 31,561 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2315000/Python3-freq-table | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
freq = defaultdict(int)
for m, s in zip(messages, senders): freq[s] += len(m.split())
return max(freq, key=lambda x: (freq[x], x)) | sender-with-largest-word-count | [Python3] freq table | ye15 | 0 | 13 | sender with largest word count | 2,284 | 0.561 | Medium | 31,562 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2305816/Easy-python-Hashmap-%2B-count-spaces | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
sender_dict={}
max_count = 0
for mess in range(len(messages)):
space_count=1
for i in messages[mess]:
if i == ' ':
space_count+=1
... | sender-with-largest-word-count | Easy python - Hashmap + count spaces | sunakshi132 | 0 | 20 | sender with largest word count | 2,284 | 0.561 | Medium | 31,563 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2262796/Python-4-Liner | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d = defaultdict(int)
for m, s in zip(messages, senders):
d[s] += len(m.split())
return sorted(d.items(), key=lambda t: (t[1], t[0]))[-1][0] | sender-with-largest-word-count | Python 4-Liner | amaargiru | 0 | 28 | sender with largest word count | 2,284 | 0.561 | Medium | 31,564 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2214898/Python-top-90-solution | class Solution:
def largestWordCount(self, msg: List[str], snd: List[str]) -> str:
ans = {x:0 for x in snd}
for i in range(len(msg)):
ans[snd[i]] += len(msg[i].split())
sender = ''
mx = ans[max(ans, key=ans.get)]
for k, v in ans.items():
if v == mx and... | sender-with-largest-word-count | Python top 90% solution | StikS32 | 0 | 42 | sender with largest word count | 2,284 | 0.561 | Medium | 31,565 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2131538/Python-oror-Straight-Forward | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
msgCount = defaultdict(int)
for msg, friend in zip(messages,senders):
msg = msg.split()
msgCount[friend] += len(msg)
def lexi(w1,w2):
n, m = len(w1), len(w2)
for i in range(max(n,m)):
if i >= len(w2): re... | sender-with-largest-word-count | Python || Straight Forward | morpheusdurden | 0 | 36 | sender with largest word count | 2,284 | 0.561 | Medium | 31,566 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2093542/python-3-oror-4-line-hash-map-solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
words = collections.Counter()
for message, sender in zip(messages, senders):
words[sender] += message.count(' ') + 1
return max(words, key=lambda sender: (words[sender], sender)) | sender-with-largest-word-count | python 3 || 4 line hash map solution | dereky4 | 0 | 38 | sender with largest word count | 2,284 | 0.561 | Medium | 31,567 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2091924/Python-6-lines-using-dictionary | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
mp = defaultdict(int)
mx = 0
for s, m in zip(senders, messages):
mp[s] += len(m.split())
mx = max(mx, mp[s])
return max(k for k, v in mp.items() i... | sender-with-largest-word-count | Python 6 lines using dictionary | SmittyWerbenjagermanjensen | 0 | 32 | sender with largest word count | 2,284 | 0.561 | Medium | 31,568 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2089518/Python3-Straigth-Forward-Solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
word_count_map = {} # { person, word_count }
n = len(messages)
for i in range(n):
if senders[i] in word_count_map:
word_count_map[senders[i]] += len(messa... | sender-with-largest-word-count | Python3 Straigth Forward Solution | shtanriverdi | 0 | 19 | sender with largest word count | 2,284 | 0.561 | Medium | 31,569 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2088383/python-java-easy-hash | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
ans = dict()
for m, s in zip(messages, senders) :
words = m.count(' ') + 1
if s in ans : ans[s] += words
else : ans[s] = words
sender = ""
words = 0
for s, w in ans.items()... | sender-with-largest-word-count | python, java - easy hash | ZX007java | 0 | 13 | sender with largest word count | 2,284 | 0.561 | Medium | 31,570 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2086557/Python-or-Easy-Solution-or-Dictionary | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
wordCount={}
n=len(senders)
ans=0
res=""
for i in range(n):
if senders[i] not in wordCount:
wordCount[senders[i]]=messages[i].count(' ')+1
else:... | sender-with-largest-word-count | Python | Easy Solution | Dictionary | backpropagator | 0 | 16 | sender with largest word count | 2,284 | 0.561 | Medium | 31,571 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2085619/Easy-to-understand-Python-Solution-with-explanation | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
# store count of words of each message in dictionary
# key=senders[i] and value=count of words in messages send by sender[i]
ans = {}
for i in range(len(messages)):
count_words = len(messages[i].split())
if sender... | sender-with-largest-word-count | Easy to understand Python Solution with explanation | harshkanani014 | 0 | 13 | sender with largest word count | 2,284 | 0.561 | Medium | 31,572 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2085083/Decent-Python-solution-using-Dictionary | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
dicti = {}
n = len(senders)
maxi = 0
arr = []
while n != 0:
cnt = messages[n-1].count(' ') + 1
if senders[n-1] not in dicti:
dicti[senders[n-1]]... | sender-with-largest-word-count | Decent Python solution using Dictionary | onyxspk | 0 | 6 | sender with largest word count | 2,284 | 0.561 | Medium | 31,573 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084480/Python-Simple-Solution-or-4-lines | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
hm = {}
for message,sender in zip(messages, senders):
hm[sender] = hm.get(sender, 0) + len(message.split(' '))
return sorted(list(hm.items()),key = lambda x: (x[1],x[0]), reverse=True)[0][... | sender-with-largest-word-count | Python Simple Solution | 4 lines | Nk0311 | 0 | 12 | sender with largest word count | 2,284 | 0.561 | Medium | 31,574 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084323/Solution-using-Hashmap-in-python | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
r = [len(i.split(" ")) for i in messages]
d = {}
for i in range(len(messages)):
if senders[i] in d:
d[senders[i]] += r[i]
else:
d[senders[i]] = ... | sender-with-largest-word-count | Solution using Hashmap in python | srija100 | 0 | 10 | sender with largest word count | 2,284 | 0.561 | Medium | 31,575 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084225/Python-3-String-Split-and-HashMap | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
maps = defaultdict(int)
for me, s in zip(messages, senders):
words = len(me.split(" "))
maps[s] += words
ans = "1"*11
m = 0
for sender in senders:
... | sender-with-largest-word-count | [Python 3] - String Split and HashMap | hari19041 | 0 | 15 | sender with largest word count | 2,284 | 0.561 | Medium | 31,576 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084055/Python-solution-using-Dictionary-and-sorting | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d = {}
# combine messages and senders into a dictionary
for item in range(len(messages)):
key = senders[item]
value = messages[item]
# if key already exist... | sender-with-largest-word-count | Python solution using Dictionary and sorting | __sushi__ | 0 | 15 | sender with largest word count | 2,284 | 0.561 | Medium | 31,577 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2084014/Python-or-Hashmap | class Solution:
def largestWordCount(self, mes: List[str], se: List[str]) -> str:
d = {}
for i in range(len(mes)):
l = mes[i].split(" ")
if d.get(se[i]):
d[se[i]] += len(l)
else:
d[se[i]] = len(l)
t = 0
ans = []
... | sender-with-largest-word-count | Python | Hashmap | Shivamk09 | 0 | 16 | sender with largest word count | 2,284 | 0.561 | Medium | 31,578 |
https://leetcode.com/problems/sender-with-largest-word-count/discuss/2083926/Python3-simple-solution | class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
d,res,s = {},-1,""
for i in range(len(senders)):
sender = senders[i]
message_count = len(messages[i].split(" "))
d[sender] = d.get(sender,0) + message_count
if ... | sender-with-largest-word-count | Python3 simple solution | abhijeetmallick29 | 0 | 9 | sender with largest word count | 2,284 | 0.561 | Medium | 31,579 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2083990/Very-simple-Python-solution-O(nlog(n)) | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
Arr = [0] * n # i-th city has Arr[i] roads
for A,B in roads:
Arr[A] += 1 # Each road increase the road count
Arr[B] += 1
Arr.sort() # Cities with most road should receive the most sc... | maximum-total-importance-of-roads | Very simple Python solution O(nlog(n)) | Eba472 | 14 | 452 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,580 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2086722/Python3-or-Easy-understanding-or-Faster-than-100-time-and-memory | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
'''The main idea is to count the frequency of the cities connected to roads and then
keep on assigning the integer value from one to n to each cities after sorting it. '''
f = [0 for _ i... | maximum-total-importance-of-roads | Python3 | Easy understanding | Faster than 100% time and memory | shodan11 | 2 | 50 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,581 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2084168/Python-Easy-Solution-using-Sort | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
degrees = [0] * n
for x,y in roads:
degrees[x] += 1
degrees[y] += 1
degrees.sort() # Cities with most roads would receive the most score
return sum(degrees[i] * (i+... | maximum-total-importance-of-roads | Python Easy Solution using Sort | constantine786 | 2 | 52 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,582 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2554456/Python-Simple-solution-Optimized | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
in_deg = [0]*n
for u, v in roads:
in_deg[u] += 1
in_deg[v] += 1
return sum([deg*i for i, deg in enumerate(sorted(in_deg), start=1)]) | maximum-total-importance-of-roads | Python Simple solution Optimized | sujittiwari | 0 | 24 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,583 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2315001/Python3-greedy | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
degree = [0]*n
for u, v in roads:
degree[u] += 1
degree[v] += 1
return sum(x*y for x, y in zip(range(1, n+1), sorted(degree))) | maximum-total-importance-of-roads | [Python3] greedy | ye15 | 0 | 15 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,584 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2131543/Python-oror-Very-Easy-Solution | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
connexions = defaultdict(int)
for i,j in roads:
connexions[i] += 1
connexions[j] += 1
val , node = connexions.values(), connexions.keys()
assign = defaultdict(int)
ans = 0
for v,no in sorted(zip(val,node), reverse =... | maximum-total-importance-of-roads | Python || Very Easy Solution | morpheusdurden | 0 | 40 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,585 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2091366/java-python-simple-easy-small-and-fast | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
g = [0]*n
for r in roads :
g[r[0]] += 1
g[r[1]] += 1
g.sort()
sum = 0
for i in range (n):
sum += g[i]*(i+1)
return sum | maximum-total-importance-of-roads | java, python - simple, easy, small & fast | ZX007java | 0 | 29 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,586 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2086044/Python-or-6-Lines-or-Sort-%2B-Counter | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
indegrees = Counter()
for src, dst in roads:
indegrees[src] += 1
indegrees[dst] += 1
indegrees = sorted(indegrees.values(), reverse=True)
return sum((n - i) * degree for i, deg... | maximum-total-importance-of-roads | Python | 6 Lines | Sort + Counter | leeteatsleep | 0 | 16 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,587 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2084446/Python-Solution-O(n) | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
graph = {i: [] for i in range(n)}
for x, y in roads:
graph[x].append(y)
graph[y].append(x)
c = defaultdict(list)
for node in graph:
c[len(grap... | maximum-total-importance-of-roads | Python Solution O(n) | user6397p | 0 | 7 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,588 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2084383/Simple-Python-Solution | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
degree = [0]*n
for i,j in roads:
degree[i]+=1
degree[j]+=1
degree.sort()
score = 0
for j in range(n):
score+=degree[j]*(j+1)
return score | maximum-total-importance-of-roads | Simple Python Solution | srija100 | 0 | 6 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,589 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2084039/Python-or-Greedy | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
ind = [0 for i in range(n)]
dis = [0 for i in range(n)]
for val in roads:
ind[val[0]] += 1
ind[val[1]] += 1
l = []
for i in range(n):
l.append([i,ind[i]])
... | maximum-total-importance-of-roads | Python | Greedy | Shivamk09 | 0 | 10 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,590 |
https://leetcode.com/problems/maximum-total-importance-of-roads/discuss/2083963/solution-without-graphs-and-other-complex-terms | class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
dict1={}
for i in roads:
if i[0] not in dict1:dict1[i[0]]=1
else:dict1[i[0]]+=1
if i[1] not in dict1:dict1[i[1]]=1
else:dict1[i[1]]+=1
sorted_dict = {}
... | maximum-total-importance-of-roads | solution without graphs, and other complex terms | alenov | 0 | 5 | maximum total importance of roads | 2,285 | 0.608 | Medium | 31,591 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2085849/Python-Two-Liner-Beats-~95 | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
counter_s = Counter(s)
return min(counter_s[c] // count for c,count in Counter(target).items()) | rearrange-characters-to-make-target-string | Python Two Liner Beats ~95% | constantine786 | 14 | 854 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,592 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2113253/Two-Counters | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
cnt, cnt1 = Counter(s), Counter(target)
return min(cnt[ch] // cnt1[ch] for ch in cnt1.keys()) | rearrange-characters-to-make-target-string | Two Counters | votrubac | 2 | 155 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,593 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2087665/Python-two-Counters | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
s = Counter(s)
target = Counter(target)
return min(s[c] // target[c] for c in target) | rearrange-characters-to-make-target-string | Python, two Counters | blue_sky5 | 2 | 46 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,594 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2085846/Python-or-Stright-Forward | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
counter_s = Counter(s)
res = float('inf')
for k, v in Counter(target).items():
res = min(res, counter_s[k] // v)
return res | rearrange-characters-to-make-target-string | Python | Stright Forward | yzhao156 | 2 | 117 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,595 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2085788/Simple-Python-solution | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
freqs = {} # count the letter ffrequency of string s
for char in s:
freqs[char] = freqs.get(char,0) + 1
freqTarget = {} # count the letter ffrequency of target s
for c in target:
... | rearrange-characters-to-make-target-string | Simple Python solution | Eba472 | 2 | 251 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,596 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2098732/Python-3-Counter-HashMap-Easy-Solution-beats-99 | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
count1 = Counter(target)
count2 = Counter(s)
s = inf
for char in count1:
if char not in count2:
return 0
s = min(s, count2[char]//count1[char])
return s | rearrange-characters-to-make-target-string | [Python 3] - Counter HashMap - Easy Solution - beats 99% | hari19041 | 1 | 62 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,597 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2743330/Python3-or-Brute-Force | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
S = Counter(s)
ans = 0
while True:
for i in target:
if S[i] > 0:
S[i] -= 1
else:
return ans
ans += 1
return 0
... | rearrange-characters-to-make-target-string | Python3 | Brute Force | iftesamnabi | 0 | 9 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,598 |
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2482587/Python-for-beginners-(1)-Naive-(2)-Optimized-(Counter) | class Solution:
def rearrangeCharacters(self, s: str, target: str) -> int:
#Naive Approach
#Runtime:59ms
dic={}
for i in s:
dic[i]=dic.get(i,0)+1
#print(dic) # The frequency of all the alphabets
count=0
while sum(dic.values())>=len(targ... | rearrange-characters-to-make-target-string | Python for beginners (1) Naive (2) Optimized (Counter) | mehtay037 | 0 | 75 | rearrange characters to make target string | 2,287 | 0.578 | Easy | 31,599 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.