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/largest-positive-integer-that-exists-with-its-negative/discuss/2811332/Memory-Sparing-Algorithm-Space-Complexity-O(1)
class Solution: def findMaxK(self, nums: List[int]) -> int: nums.sort(reverse=True, key=lambda x: (abs(x)-0.5) if x < 0 else abs(x)) i = 0 while i < len(nums)-1: if nums[i] == -nums[i+1]: return nums[i] i += 1 return -1
largest-positive-integer-that-exists-with-its-negative
Memory Sparing Algorithm - Space Complexity O(1)
Mik-100
0
2
largest positive integer that exists with its negative
2,441
0.678
Easy
33,400
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2806214/Python-Beginner-Friendly
class Solution: def findMaxK(self, nums: List[int]) -> int: temp = nums.copy() while temp: our_max = max(temp) if (our_max * -1) in temp: return our_max else: temp.remove(our_max) return -1
largest-positive-integer-that-exists-with-its-negative
Python - Beginner Friendly
AbhiP5
0
2
largest positive integer that exists with its negative
2,441
0.678
Easy
33,401
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2790741/Python-beats-90
class Solution: def findMaxK(self, nums: List[int]) -> int: list1 = [i for i in nums if i > 0] list2 = [i for i in nums if i < 0] list3 = [] for e in list1: for k in list2: if e == -k: list3.append(e) if len(list3) > 0: return max(list3) else: return -1
largest-positive-integer-that-exists-with-its-negative
Python beats 90%
DubanaevaElnura
0
5
largest positive integer that exists with its negative
2,441
0.678
Easy
33,402
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2766991/easy-solution
class Solution: def findMaxK(self, nums: List[int]) -> int: l=sorted(nums) i=len(nums)-1 while i >=0: s=l[i] if -s in l: return s else: i=i-1 else: return -1
largest-positive-integer-that-exists-with-its-negative
easy solution
sindhu_300
0
6
largest positive integer that exists with its negative
2,441
0.678
Easy
33,403
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2761614/Python-Simple-Solution-using-Dictionary
class Solution: def findMaxK(self, nums: List[int]) -> int: result = -1 counts = Counter(nums) for num in nums: if -num in counts: result = max(result, abs(num)) return result
largest-positive-integer-that-exists-with-its-negative
Python Simple Solution using Dictionary
bettend
0
8
largest positive integer that exists with its negative
2,441
0.678
Easy
33,404
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2745834/Python-2-liner-using-Sets-Easy-to-Understand
class Solution: def findMaxK(self, nums: List[int]) -> int: s = {i for i in nums if -i in nums} return max(s) if s else -1
largest-positive-integer-that-exists-with-its-negative
Python 2 liner using Sets - Easy to Understand
jacobsimonareickal
0
10
largest positive integer that exists with its negative
2,441
0.678
Easy
33,405
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2722517/Python-3-two-approaches-using-slinding-window-and-hashset
class Solution: def findMaxK(self, nums: List[int]) -> int: l = 0 maxnum = -1 length = len(nums) nums = sorted(nums , key = abs) for r in range(1, length): if nums[l] + nums[r] == 0: maxnum = max(maxnum, abs(nums[l])) l += 1 return maxnum
largest-positive-integer-that-exists-with-its-negative
Python 3 two approaches using slinding window and hashset
theReal007
0
10
largest positive integer that exists with its negative
2,441
0.678
Easy
33,406
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2722517/Python-3-two-approaches-using-slinding-window-and-hashset
class Solution: def findMaxK(self, nums: List[int]) -> int: s = set() maxnum = -1 for n in nums: if -1 * n not in s: s.add(n) else: maxnum = max(maxnum, abs(n)) return maxnum
largest-positive-integer-that-exists-with-its-negative
Python 3 two approaches using slinding window and hashset
theReal007
0
10
largest positive integer that exists with its negative
2,441
0.678
Easy
33,407
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2714423/Python-Easy-solution
class Solution: def findMaxK(self, nums: List[int]) -> int: nums.sort(reverse=True) for num in nums: if -num in nums: return num return -1
largest-positive-integer-that-exists-with-its-negative
Python Easy solution
mg_112002
0
5
largest positive integer that exists with its negative
2,441
0.678
Easy
33,408
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2713537/Python-simple-solution
class Solution: def findMaxK(self, nums: List[int]) -> int: for i in sorted(nums): if i*-1 in nums: return abs(i) return -1
largest-positive-integer-that-exists-with-its-negative
Python simple solution
StikS32
0
11
largest positive integer that exists with its negative
2,441
0.678
Easy
33,409
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2713285/Python3-100-faster-with-explanation
class Solution: def findMaxK(self, nums: List[int]) -> int: numDict, trueDict = {}, {} for x in nums: if x * -1 in numDict: trueDict[abs(x)] = True elif x not in numDict: numDict[x] = False if trueDict: return max(trueDict) else: return -1
largest-positive-integer-that-exists-with-its-negative
Python3, 100% faster with explanation
cvelazquez322
0
11
largest positive integer that exists with its negative
2,441
0.678
Easy
33,410
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2711942/Sorting-by-absolute-value
class Solution: def findMaxK(self, nums: List[int]) -> int: sorted_num = sorted(nums, key=lambda n: (abs(n), n), reverse=True) nums_length = len(nums) print(sorted_num) for i, n in enumerate(sorted_num[:-1]): if n > 0: if n + sorted_num[i+1] == 0: return n return -1
largest-positive-integer-that-exists-with-its-negative
Sorting by absolute value
puremonkey2001
0
8
largest positive integer that exists with its negative
2,441
0.678
Easy
33,411
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2711913/Python-Easy-to-understand-2-sets
class Solution: def findMaxK(self, nums: List[int]) -> int: neg = set() pos = set() for num in nums: if num < 0: neg.add(num * -1) else: pos.add(num) overlap = neg &amp; pos return max(overlap) if len(overlap) > 0 else -1
largest-positive-integer-that-exists-with-its-negative
Python - Easy to understand 2 sets
ptegan
0
5
largest positive integer that exists with its negative
2,441
0.678
Easy
33,412
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2710938/O(n)-Time-using-Set
class Solution: def findMaxK(self, nums: List[int]) -> int: numsSet = set(nums) result = float('-inf') for num in nums: if num > result and num * -1 in numsSet: result = num return result if result != float('-inf') else -1
largest-positive-integer-that-exists-with-its-negative
O(n) Time using Set
ChaseDho
0
10
largest positive integer that exists with its negative
2,441
0.678
Easy
33,413
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2710808/Python3-2-line
class Solution: def findMaxK(self, nums: List[int]) -> int: seen = set(nums) return max((abs(x) for x in seen if -x in seen), default=-1)
largest-positive-integer-that-exists-with-its-negative
[Python3] 2-line
ye15
0
9
largest positive integer that exists with its negative
2,441
0.678
Easy
33,414
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2710350/Python-simple-3-lines
class Solution: def findMaxK(self, nums: List[int]) -> int: numsSet = set(nums) try: return max(n for n in numsSet if -n in numsSet) except: return -1
largest-positive-integer-that-exists-with-its-negative
Python simple 3 lines
SmittyWerbenjagermanjensen
0
11
largest positive integer that exists with its negative
2,441
0.678
Easy
33,415
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2710028/Python-two-sum-like.-O(N)O(N)
class Solution: def findMaxK(self, nums: List[int]) -> int: d = set() result = -1 for n in nums: if -n in d: result = max(result, abs(n)) else: d.add(n) return result
largest-positive-integer-that-exists-with-its-negative
Python, two-sum like. O(N)/O(N)
blue_sky5
0
7
largest positive integer that exists with its negative
2,441
0.678
Easy
33,416
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2709610/python-simple-solution!
class Solution: def findMaxK(self, nums: List[int]) -> int: ans = [] tmps = set(nums) for tmp in tmps: if -(tmp) in tmps: ans.append(tmp) return -1 if len(ans) == 0 else max(ans)
largest-positive-integer-that-exists-with-its-negative
python simple solution!
peter19930419
0
4
largest positive integer that exists with its negative
2,441
0.678
Easy
33,417
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2709442/simple-iteration-with-extra-space-and-0(n)-time-complexity
class Solution: def findMaxK(self, nums: List[int]) -> int: l=[] l1=[] for i in nums: if i>0: l.append(i) for j in l: if -j in nums: l1.append(j) if l1: return max(l1) else: return -1
largest-positive-integer-that-exists-with-its-negative
simple iteration with extra space and 0(n) time complexity
insane_me12
0
3
largest positive integer that exists with its negative
2,441
0.678
Easy
33,418
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2709147/Easy-Python3-Solution
class Solution: def findMaxK(self, nums: List[int]) -> int: res = -1 for num in nums: if num > 0 and -num in nums: res = max(res, num) return res
largest-positive-integer-that-exists-with-its-negative
Easy Python3 Solution
mediocre-coder
0
4
largest positive integer that exists with its negative
2,441
0.678
Easy
33,419
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2709000/Python3-One-Liner
class Solution: def findMaxK(self, nums: List[int]) -> int: return max([i for i in nums if -i in nums] + [-1])
largest-positive-integer-that-exists-with-its-negative
Python3 One Liner
godshiva
0
3
largest positive integer that exists with its negative
2,441
0.678
Easy
33,420
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708941/Python-or-Set-or-O(n)-time-and-space
class Solution: def findMaxK(self, nums: List[int]) -> int: xs = set(nums) largest = float('-inf') for x in nums: if x > 0 and -x in xs: largest = max(largest, x) return -1 if largest == float('-inf') else largest
largest-positive-integer-that-exists-with-its-negative
Python | Set | O(n) time and space
on_danse_encore_on_rit_encore
0
5
largest positive integer that exists with its negative
2,441
0.678
Easy
33,421
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708888/Python-brute-force-1-line
class Solution: def findMaxK(self, nums: List[int]) -> int: M={abs(x) for x in nums if -x in nums} return -1 if not M else max(M)
largest-positive-integer-that-exists-with-its-negative
Python, brute force 1 line
Leox2022
0
5
largest positive integer that exists with its negative
2,441
0.678
Easy
33,422
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708873/largest-positive-integer-that-exists-with-its-negative
class Solution: def findMaxK(self, nums: List[int]) -> int: se=set() ans=-1 for i in nums: se.add(i) for i in nums: if i>0: if -i in se: ans=max(ans,i) return ans
largest-positive-integer-that-exists-with-its-negative
largest-positive-integer-that-exists-with-its-negative
shivansh2001sri
0
4
largest positive integer that exists with its negative
2,441
0.678
Easy
33,423
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708402/Python-Answer-Using-Dictionary-Counter
class Solution: def findMaxK(self, nums: List[int]) -> int: c = Counter(nums) for n in reversed(sorted(c.keys())): if n <= 0: return -1 if -n in c: return n return -1
largest-positive-integer-that-exists-with-its-negative
[Python Answer🀫🐍🐍🐍] Using Dictionary Counter
xmky
0
9
largest positive integer that exists with its negative
2,441
0.678
Easy
33,424
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708292/Python3-Set
class Solution: def findMaxK(self, nums: List[int]) -> int: s=set(nums) while s: m=max(s) if -m in s: return m s.remove(m) return -1
largest-positive-integer-that-exists-with-its-negative
Python3, Set
Silvia42
0
8
largest positive integer that exists with its negative
2,441
0.678
Easy
33,425
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708170/Python-Simple-Python-Solution-or-100-Faster
class Solution: def findMaxK(self, nums: List[int]) -> int: nums = sorted(nums) index = len(nums)-1 while index > -1: num = nums[index] if -num in nums: return num index = index - 1 return -1
largest-positive-integer-that-exists-with-its-negative
[ Python ] βœ…βœ… Simple Python Solution | 100% Faster πŸ₯³βœŒπŸ‘
ASHOK_KUMAR_MEGHVANSHI
0
37
largest positive integer that exists with its negative
2,441
0.678
Easy
33,426
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708127/python-solution
class Solution: def findMaxK(self, nums: List[int]) -> int: l=[] for i in nums: s=-1*i if s in nums: l.append(i) if len(l)==0: return -1 maxi=l[0] for i in l: if i>maxi: maxi=i return maxi
largest-positive-integer-that-exists-with-its-negative
python solution
shashank_2000
0
15
largest positive integer that exists with its negative
2,441
0.678
Easy
33,427
https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/2708026/Python-Easy-Solution
class Solution: def findMaxK(self, nums: List[int]) -> int: nums.sort() i = len(nums) - 1 while i >= 0: tmp = nums[i] if -tmp in nums: return tmp else: i -= 1 return -1
largest-positive-integer-that-exists-with-its-negative
Python - Easy Solution
blazers08
0
24
largest positive integer that exists with its negative
2,441
0.678
Easy
33,428
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708055/One-Liner-or-Explained
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set([int(str(i)[::-1]) for i in nums] + nums))
count-number-of-distinct-integers-after-reverse-operations
One Liner | Explained
lukewu28
5
427
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,429
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2730102/Easy-solution-using-set-oror-python-4-liner
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: n=len(nums) #traversing through loop for i in range(n): nums.append(int(str(nums[i])[::-1])) #using string slicing and appending reverse of the number at end return len(set(nums)) #returning the length of set to get unique value count
count-number-of-distinct-integers-after-reverse-operations
Easy solution using set || python 4 liner
amazing_abizer
2
69
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,430
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2755793/SIMPLE-SOLUTION-oror-TS%3A-O-(N)O(N)
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: dct=defaultdict(lambda :0) for num in nums: dct[num]=1 for num in nums: rev=int(str(num)[::-1]) if dct[rev]!=1: dct[rev]=1 return len(dct)
count-number-of-distinct-integers-after-reverse-operations
SIMPLE SOLUTION || T/S: O (N)/O(N)
beneath_ocean
1
20
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,431
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708237/Python-O(nlog(n))-and-1-liner-O(n2)
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: def reverse(n): rem = 0 while n!=0: digit = n%10 n = n//10 rem = rem*10+digit return rem rev_list = [] for n in nums: rev_list.append(reverse(n)) nums = set(nums+rev_list) return len(nums)
count-number-of-distinct-integers-after-reverse-operations
Python O(nlog(n)) and 1-liner O(n^2)
diwakar_4
1
16
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,432
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708237/Python-O(nlog(n))-and-1-liner-O(n2)
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set(nums+[int(str(n)[::-1]) for n in nums]))
count-number-of-distinct-integers-after-reverse-operations
Python O(nlog(n)) and 1-liner O(n^2)
diwakar_4
1
16
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,433
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2846849/python-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: l_out = [] for i in nums: j = str(i) j = j[::-1] l_out.append(i) l_out.append(int(j)) s = set(l_out) return len(s)
count-number-of-distinct-integers-after-reverse-operations
python solution
HARMEETSINGH0
0
1
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,434
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2843208/Python-98-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: original_length = len(nums) for i in range(original_length): nums.append(int(str(nums[i])[::-1])) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Python 98% solution
Bread0307
0
2
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,435
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2842281/Simple-python-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: res = [] for elem in nums: res.append(int(str(elem)[::-1])) nums.extend(res) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Simple python solution
Rajeev_varma008
0
3
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,436
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2823543/Python-3-oror-4-lines-of-code-oror-Beginner-Friendly
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: rev_nums = [int(str(i)[::-1]) for i in nums] final=nums+rev_nums s=set(final) return len(s)
count-number-of-distinct-integers-after-reverse-operations
Python 3πŸ”₯ || 4 lines of codeβœ… || Beginner Friendly✌🏼
jhadevansh0809
0
2
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,437
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2818933/Python-3-or-using-set-union-operator-%22or%22
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set(nums)|{int(str(n)[::-1]) for n in nums})
count-number-of-distinct-integers-after-reverse-operations
Python 3 | using set union operator "|"
0xack13
0
1
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,438
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2818619/Simple-Python-Solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: numbers = [] for num in nums: numbers += [int(str(num)[::-1])] nums += numbers return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Simple Python Solution
PranavBhatt
0
4
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,439
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2793022/Python-1-line-code
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set([int(str(x)[::-1]) for x in nums]+nums))
count-number-of-distinct-integers-after-reverse-operations
Python 1 line code
kumar_anand05
0
5
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,440
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2792132/Python3%3A-Easy-to-understand
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: L = len(nums) for i in range(L): temp = 0 num = nums[i] while num > 0: mod = num % 10 num //= 10 temp = temp * 10 + mod nums.append(temp) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Python3: Easy to understand
mediocre-coder
0
1
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,441
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2780554/Python-divmod-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: l = [] for num in nums: rev = 0 while num: num, carry = divmod(num, 10) rev = rev * 10 + carry l.append(rev) return len(set(nums+l))
count-number-of-distinct-integers-after-reverse-operations
Python divmod solution
kruzhilkin
0
4
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,442
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2771766/python-solution-Count-Number-of-Distinct-Integers-After-Reverse-Operations
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: def reverse(num): new_num = num % 10 num = num // 10 while num: t = num % 10 num = num//10 new_num = new_num * (10**1) + t return new_num l = [] for num in nums: l.append(reverse(num)) l.extend(nums) return len(set(l))
count-number-of-distinct-integers-after-reverse-operations
python solution Count Number of Distinct Integers After Reverse Operations
sarthakchawande14
0
3
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,443
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2770283/Python-Easy-and-Intuitive-Solution.
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: def helper(n): number = 0 while n > 0: digit = n % 10 number *= 10 number += digit n = n // 10 return number length = len(nums) for i in range(length): nums.append(helper(nums[i])) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Python Easy & Intuitive Solution.
MaverickEyedea
0
5
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,444
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2751453/One-pass-over-set-of-nums-96-speed
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: set_nums, reversed_nums = set(nums), set() for n in set_nums: if n > 9: reversed_nums.add(int(str(n)[::-1])) return len(set_nums | reversed_nums)
count-number-of-distinct-integers-after-reverse-operations
One pass over set of nums, 96% speed
EvgenySH
0
4
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,445
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2747087/Python3-Solution-with-using-hashset
class Solution: def reverse_num(self, num): r_num = 0 while num: r_num *= 10 r_num += num % 10 num //= 10 return r_num def countDistinctIntegers(self, nums: List[int]) -> int: s = set() for num in nums: s.add(num) s.add(self.reverse_num(num)) return len(s)
count-number-of-distinct-integers-after-reverse-operations
[Python3] Solution with using hashset
maosipov11
0
2
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,446
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2735389/More-than-90-better-in-space-and-time-complexity
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: for i in range(len(nums)): if nums[i] > 9: n = int(f"{nums[i]}"[::-1]) else: n = nums[i] nums.append(n) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
More than 90% better in space and time complexity
fazliddindehkanoff
0
8
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,447
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2729536/Python-Solution-Understandable
class Solution: def reverseString(self, num): #function for reversing the string res = "" while num > 0: num, mo = divmod(num, 10) #takes the last number as mo and the remaining number as num res += str(mo) num = num return int(res.lstrip()) #to control if there are any leading zeros def countDistinctIntegers(self, nums: List[int]) -> int: for i in range(len(nums)): nums.append(self.reverseString(nums[i])) #print(nums) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Python Solution Understandable
pandish
0
3
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,448
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2723355/Python3-Two-Line-or-str()-or-95-runtime-or-simple-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: for i in range(len(nums)): # i = str(nums[i]) nums.append(int(str(nums[i])[::-1])) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Python3 Two Line | str() | 95% runtime | simple solution
Gaurav_Phatkare
0
10
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,449
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2722004/python-easy-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: for i in range(len(nums)): x=str(nums[i]) x=x[::-1] while x[0]==0: x.pop(0) nums.append(int(x)) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
python easy solution
AviSrivastava
0
3
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,450
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2719530/python-Easy-to-understand
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: l=len(nums) for i in range(l): nums.append(int(str(nums[i])[::-1])) nums=set(nums) return len(nums)
count-number-of-distinct-integers-after-reverse-operations
python Easy to understand
Narendrasinghdangi
0
2
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,451
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2713343/Python-Set-Solution-or-StraightForward
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: lst = list(set(nums)) rvrs = [int(str(i)[::-1]) for i in lst] return len(set(rvrs + lst))
count-number-of-distinct-integers-after-reverse-operations
Python Set Solution | StraightForward
cyber_kazakh
0
6
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,452
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2712651/Python3-One-line
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set(nums + [int(str(num)[::-1]) for num in nums]))
count-number-of-distinct-integers-after-reverse-operations
Python3 One line
frolovdmn
0
8
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,453
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2710824/Python3-1-line
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set(nums) | {int(str(x)[::-1]) for x in nums})
count-number-of-distinct-integers-after-reverse-operations
[Python3] 1-line
ye15
0
3
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,454
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2710374/Python-without-using-str()
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: def reverseNum(n): revN = 0 while n: revN = revN * 10 + n % 10 n //= 10 return revN return len( set(nums) | set(reverseNum(n) for n in nums) )
count-number-of-distinct-integers-after-reverse-operations
Python without using str()
SmittyWerbenjagermanjensen
0
7
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,455
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2709739/Python-simple-solution!
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: tmp = [] for num in nums: tmp.append(int(str(num)[::-1])) ans = nums + tmp return len(set(ans))
count-number-of-distinct-integers-after-reverse-operations
Python simple solution!
peter19930419
0
3
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,456
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2709203/Simple-and-Easy-to-Understand-or-Beginner's-Friendly-or-Python
class Solution(object): def countDistinctIntegers(self, nums): def rev(n): ans = 0 while n != 0: ans = ans * 10 + (n % 10) n = n // 10 return ans for i in range(len(nums)): nums.append(rev(nums[i])) return len(set(nums))
count-number-of-distinct-integers-after-reverse-operations
Simple and Easy to Understand | Beginner's Friendly | Python
its_krish_here
0
9
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,457
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2709102/Python-brute-force
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: nums=set(nums) return len({int(str(x)[::-1]) for x in nums}.union(nums))
count-number-of-distinct-integers-after-reverse-operations
Python, brute force
Leox2022
0
2
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,458
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708583/Python-or-Map-or-Set
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: s=list(map(str,nums)) # print(s) reverse = lambda i : i[::-1] g=list(map(reverse,s)) # print(g) glo=set(s) glo=glo.union(set(g)) # print(glo) newg=list(map(int,glo)) return len(list(set(newg)))
count-number-of-distinct-integers-after-reverse-operations
Python | Map | Set
Prithiviraj1927
0
9
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,459
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708507/Python-Answer-Set-and-string-reverse-Answer
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: s = set(nums) n = { int(str(i)[::-1]) for i in nums} s.update(n) return len(s)
count-number-of-distinct-integers-after-reverse-operations
[Python Answer🀫🐍🐍🐍] Set and string reverse Answer
xmky
0
6
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,460
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708280/Python-Simple-Python-Solution-Using-Simple-Loop-and-Set
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: reverse = [] for num in nums: num = int(str(num)[::-1]) reverse.append(num) result = set(nums + reverse) return len(result)
count-number-of-distinct-integers-after-reverse-operations
[ Python ] βœ…βœ… Simple Python Solution Using Simple Loop and Set πŸ₯³βœŒπŸ‘
ASHOK_KUMAR_MEGHVANSHI
0
13
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,461
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708273/python-solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: arr=[] for i in nums: arr.append(int(str(i)[::-1])) return len(set(nums+arr))
count-number-of-distinct-integers-after-reverse-operations
python solution
shashank_2000
0
10
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,462
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708254/Python3-Simple-One-Line
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: return len(set(nums + [int(str(x)[::-1]) for x in nums]))
count-number-of-distinct-integers-after-reverse-operations
Python3, Simple One Line
Silvia42
0
6
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,463
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708254/Python3-Simple-One-Line
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: z=set(nums) for x in nums: z.add(int(str(x)[::-1])) return len(z)
count-number-of-distinct-integers-after-reverse-operations
Python3, Simple One Line
Silvia42
0
6
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,464
https://leetcode.com/problems/count-number-of-distinct-integers-after-reverse-operations/discuss/2708089/Python-Easy-Solution
class Solution: def countDistinctIntegers(self, nums: List[int]) -> int: tmp = [] for num in nums: tmp.append(int(str(num)[::-1])) return len(set(nums+tmp))
count-number-of-distinct-integers-after-reverse-operations
Python - Easy Solution
blazers08
0
9
count number of distinct integers after reverse operations
2,442
0.788
Medium
33,465
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708439/Python3-O(-digits)-solution-beats-100-47ms
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: digits = [] while num > 0: digits.append(num % 10) num = num // 10 digits.reverse() hi, lo = 0, len(digits) - 1 while hi <= lo: if hi == lo: if digits[hi] % 2 == 0: break else: return False if digits[hi] == digits[lo]: hi += 1 lo -= 1 elif digits[hi] == 1 and digits[hi] != digits[lo]: digits[hi] -= 1 digits[hi+1] += 10 hi += 1 if lo != hi: digits[lo] += 10 digits[lo-1] -= 1 cur = lo - 1 while digits[cur] < 0: digits[cur] = 0 digits[cur-1] -= 1 cur -= 1 elif digits[hi]-1 == digits[lo] and hi + 1 < lo: digits[hi]-= 1 digits[hi+1] += 10 hi += 1 lo -= 1 # else: # return False elif digits[hi] - 1 == digits[lo] + 10 and hi + 1 < lo: digits[hi] -= 1 digits[hi+1] += 10 digits[lo-1] -= 1 cur = lo - 1 while digits[cur] < 0: digits[cur] = 0 digits[cur-1] -= 1 cur -= 1 digits[lo] += 10 elif hi-1>=0 and lo+1<=len(digits)-1 and digits[hi-1] == 1 and digits[lo+1] == 1: digits[hi-1] -= 1 digits[hi] += 10 digits[lo+1] += 10 digits[lo] -= 1 cur = lo while digits[cur] < 0: digits[cur] = 0 digits[cur-1] -= 1 cur -= 1 lo += 1 else: return False return True
sum-of-number-and-its-reverse
[Python3] O(# digits) solution beats 100% 47ms
jfang2021
2
326
sum of number and its reverse
2,443
0.453
Medium
33,466
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2810861/Python-Easy-Solution-Faster-Than-90.43
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: def check(a,b): return b==int(str(a)[-1::-1]) t=num i=0 while i<=t: if i+t==num: if check(t,i): return True i+=1 t-=1 return False
sum-of-number-and-its-reverse
Python Easy Solution Faster Than 90.43%
DareDevil_007
1
14
sum of number and its reverse
2,443
0.453
Medium
33,467
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708597/Python3-Little-Math-Time-and-Space%3A-O(1)
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num <= 18: #Adding 1 digit number, a, and its reverse, also a: 2a if num % 2 == 0: return True #Adding 2 digit number, 10a+b, and its reverse, 10b+a: 11a+11b if num % 11 == 0: return True return False elif num <= 198: if num % 11 == 0: return True #Adding 3 digit number, 100a+10b+c, and its reverse, 100c+10b+a: 101a+20b+101c for b in range(10): newNum = (num - 20 * b) # checking last condition since a+c can be up to 18 if newNum > 0 and newNum % 101 == 0 and newNum // 101 != 19: return True return False # rest follows similar pattern elif num <= 1998: for b in range(10): newNum = (num - 20 * b) if newNum > 0 and newNum % 101 == 0 and newNum // 101 != 19: return True for bc in range(19): newNum = (num - 110 * bc) if newNum > 0 and newNum % 1001 == 0 and newNum // 1001 != 19: return True return False elif num <= 19998: for c in range(10): for bd in range(19): newNum = (num - 200 *c - 1010 * bd) if newNum > 0 and newNum % 10001 == 0 and newNum // 10001 != 19: return True for bc in range(19): newNum = (num - 110 * bc) if newNum > 0 and newNum % 1001 == 0 and newNum // 1001 != 19: return True return False elif num <= 199998: # 10**5 - 2 for c in range(10): for bd in range(19): newNum = (num - 200 *c - 1010 * bd) if newNum > 0 and newNum % 10001 == 0 and newNum // 10001 != 19: return True for cd in range(19): for be in range(19): newNum = (num - 100100 *cd - 100010 * be) if newNum > 0 and newNum % 100001 == 0 and newNum // 100001 != 19: return True return False
sum-of-number-and-its-reverse
[Python3] Little Math, Time and Space: O(1)
kkgg3781
1
61
sum of number and its reverse
2,443
0.453
Medium
33,468
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708590/sum-of-number-and-its-reverse
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: i=1 if num==0: return True while i<num: a=str(i) a=a[::-1] a=int(a) if a+i==num: return True i+=1 return False
sum-of-number-and-its-reverse
sum-of-number-and-its-reverse
meenu155
1
41
sum of number and its reverse
2,443
0.453
Medium
33,469
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708107/Python-O(nlog(n))
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True def reverse(n): rev = 0 while n!=0: rev = rev*10+n%10 n = n//10 return rev for i in range(1, num+1): if i+reverse(i) == num: return True return False
sum-of-number-and-its-reverse
Python O(nlog(n))
diwakar_4
1
33
sum of number and its reverse
2,443
0.453
Medium
33,470
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2825301/Faster-than-99
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num<19: if (not num&amp;1) or num==11: return True else: return False if num<19*11: if num%11==0: return True if num>=101: if (num-101)%20==0: return True return False if num<19*101: num1=num%101 if num1%20==0 or ((num1+101)%20==0 and num1<200): return True if num>=1001: if (num-1001)%110==0: return True return False if num<19*1001: if (num%1001)%110==0: return True if num>=10001: num1=(num-10001)%1010 if num1%200==0 or ((num1+1010)%200==0 and num1+1010<2000): return True return False num1=(num%10001)%1010 if num1%200==0 or ((num1+1010)%200==0 and num1+1010<2000): return True num1=(num%10001)+10001 if (num1%1010)%200==0 and num1<19*1010: return True num2=num1%1010+1010 if (num2%200==0) and num2<2000: return True return False
sum-of-number-and-its-reverse
Faster than 99%
mbeceanu
0
3
sum of number and its reverse
2,443
0.453
Medium
33,471
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2818954/Python-3-or-one-liner-using-any
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: return num == 0 or any(i + int(str(i)[::-1]) == num for i in range(num))
sum-of-number-and-its-reverse
Python 3 | one-liner using any
0xack13
0
3
sum of number and its reverse
2,443
0.453
Medium
33,472
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2814786/Simple-Brute-Force.
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num==0: return True for i in range(0,num): if i+int(str(i)[::-1])==num: return True return False
sum-of-number-and-its-reverse
Simple Brute Force.
Abhishek004
0
2
sum of number and its reverse
2,443
0.453
Medium
33,473
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2751580/Memorization-of-good-numbers-94-speed
class Solution: memo = set(i * 2 for i in range(10)) last = 10 def sumOfNumberAndReverse(self, num: int) -> bool: if num >= Solution.last: for n in range(Solution.last, num + 1): Solution.memo.add(n + int(str(n)[::-1])) if num in Solution.memo: Solution.last = n + 1 return True Solution.last = num + 1 return num in Solution.memo
sum-of-number-and-its-reverse
Memorization of good numbers, 94% speed
EvgenySH
0
4
sum of number and its reverse
2,443
0.453
Medium
33,474
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2729685/Python-the-one-and-only-Brute-Force-%3A)
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0:return True for i in range(num): if i + int(str(i)[::-1]) == num: return True # else it will return False by default # print(res)
sum-of-number-and-its-reverse
Python the one and only Brute-Force :)
pandish
0
12
sum of number and its reverse
2,443
0.453
Medium
33,475
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2715365/Python-Brute-ForcePrecompute-and-Cache-(77-ms)
class Solution: def sumOfNumberAndReverse(self, num: int, cache = set()) -> bool: if not cache: for i in range(100001): cache.add(i + int(str(i)[::-1])) return num in cache
sum-of-number-and-its-reverse
Python - Brute Force/Precompute & Cache (77 ms)
thedude7181
0
5
sum of number and its reverse
2,443
0.453
Medium
33,476
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2711579/Recursion-O(Log(N))-2ms-Java-solution
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: leng = len(str(num)) self.ans = False self.recur(num, 0, leng) if str(num).startswith('1') and leng>1: self.recur(num, 0, leng -1) return self.ans def recur(self, num, i, leng): if i > leng//2-1: if leng%2==1 and num%2==0 and num<20: self.ans = True else: return if i <= leng//2 - 1: for j in range(10): if num - j > 0: k = (num -j) %10 if k+j>0: tmp = j*10**(leng-2*i-1) + j + k*10**(leng-2*i-1) + k if tmp == num: self.ans = True elif tmp < num: self.recur((num-tmp)//10, i+1, leng) if self.ans == True: return
sum-of-number-and-its-reverse
Recursion O(Log(N)) 2ms Java solution
user5054z
0
14
sum of number and its reverse
2,443
0.453
Medium
33,477
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2710874/Python3-1-line
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: return any(x + int(str(x)[::-1]) == num for x in range(0, num+1))
sum-of-number-and-its-reverse
[Python3] 1-line
ye15
0
11
sum of number and its reverse
2,443
0.453
Medium
33,478
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2710578/Simple-Solution-in-Python3
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True for i in range(num//2,num): ans = str(i) if int(ans[::-1])+i == num: return True return False
sum-of-number-and-its-reverse
Simple Solution in Python3
Niranjan_15
0
12
sum of number and its reverse
2,443
0.453
Medium
33,479
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2709796/Python-simple-solution!
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: for i in range(num+1): reverse = int(str(i)[::-1]) if i + reverse == num: return True return False
sum-of-number-and-its-reverse
Python simple solution!
peter19930419
0
9
sum of number and its reverse
2,443
0.453
Medium
33,480
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2709796/Python-simple-solution!
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: return any(i + int(str(i)[::-1]) == num for i in range(num+1))
sum-of-number-and-its-reverse
Python simple solution!
peter19930419
0
9
sum of number and its reverse
2,443
0.453
Medium
33,481
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2709478/Beats-100-runtime-and-memory-wrt-python
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num==0: return True def get_difference(a,b): str_a = str(a) str_b = str(b) while str_a[-1]=="0": str_a = str_a[:-1] if len(str_a)!=len(str_b): return False j = len(str_a)-1 i = 0 while j>=0: if str_a[i]==str_b[j]: i += 1 j -= 1 else: return False return True mid = num//2 for i in range(1,mid+1): status = get_difference(num-i,i) if status: return True return False
sum-of-number-and-its-reverse
Beats 100% runtime and memory wrt python
vajja999
0
7
sum of number and its reverse
2,443
0.453
Medium
33,482
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2709433/Python3-easy-brute-force-beginner-friendly-solution
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True for i in range(num): if i + int(str(i)[::-1]) == num: return True return False
sum-of-number-and-its-reverse
Python3 easy brute force beginner friendly solution
miko_ab
0
6
sum of number and its reverse
2,443
0.453
Medium
33,483
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2709272/Python-or-Easy-Approach
class Solution: def sumOfNumberAndReverse(self, n: int) -> bool: if n == 0 : return True def check(start , end): rev = 0 while end > 0 : rev = rev* 10 + end % 10 end //= 10 if start == rev : return True return False for i in range(1 , n//2 + 1 ): start = i end = n - i if check(start, end): return True return False
sum-of-number-and-its-reverse
Python | Easy Approach
thevaibhavdixit
0
11
sum of number and its reverse
2,443
0.453
Medium
33,484
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2709146/Sum-of-Number-and-Its-Reverse-oror-Python3-oror-Easy_Solution
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num==0: return True for i in range(num): a=str(i)[::-1] if i+int(a)==num: return True return False
sum-of-number-and-its-reverse
Sum of Number and Its Reverse || Python3 || Easy_Solution
shagun_pandey
0
7
sum of number and its reverse
2,443
0.453
Medium
33,485
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708571/Brute-Force-with-Iterations-upto-num2
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if len(str(num))==1: if num%2==0: return True else: return False def func(a,b): f=str(a) g=str(b) d=len(f)-len(g) if d>0: g="0"*d+g else: f="0"*d+f if f==g[::-1]: return True return False # if f[::-1]==str(b) n=num i=0 while(n>num//2-1): if func(n,i): return True i+=1 n-=1 return False
sum-of-number-and-its-reverse
Brute Force with Iterations upto num//2
Prithiviraj1927
0
11
sum of number and its reverse
2,443
0.453
Medium
33,486
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708510/Python-Answer-Python-String-Reverse-and-Range-Power-10
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True n = len(str(num-1)) n -=2 if n < 0: n = 0 for i in range(10**(n), 10**(n+2)): if i + int(str(i)[::-1]) == num: return True return False
sum-of-number-and-its-reverse
[Python Answer🀫🐍🐍🐍] Python String Reverse and Range Power 10
xmky
0
9
sum of number and its reverse
2,443
0.453
Medium
33,487
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708242/Python-Simple-Python-Solution-Using-Simple-Loop-or-100-Faster
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True new_num = num while new_num > 0: reverse = int(str(new_num)[::-1]) if reverse + new_num == num: return True new_num = new_num - 1 return False
sum-of-number-and-its-reverse
[ Python ] βœ…βœ… Simple Python Solution Using Simple Loop | 100% Faster πŸ₯³βœŒπŸ‘
ASHOK_KUMAR_MEGHVANSHI
0
27
sum of number and its reverse
2,443
0.453
Medium
33,488
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708167/Python
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True for i in range(1, num): x = str(i) x = x[::-1] if int(x) + i == num: return True return False
sum-of-number-and-its-reverse
Python
aqxa2k
0
15
sum of number and its reverse
2,443
0.453
Medium
33,489
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708146/Python-easy-solution
class Solution: def sumOfNumberAndReverse(self, nume: int) -> bool: def reverse(no): return int(str(no)[::-1]) def sum_rev_numbere(nume): for i in range(nume + 1): if i == reverse(nume - i): return i, nume - i return None return True if sum_rev_numbere(nume) else False
sum-of-number-and-its-reverse
Python easy solution
Pramodjoshi_123
0
16
sum of number and its reverse
2,443
0.453
Medium
33,490
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708143/Python3-Simple-One-Line
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: return any(x + int(str(x)[::-1]) == num for x in range(num+1))
sum-of-number-and-its-reverse
Python3, Simple One Line
Silvia42
0
19
sum of number and its reverse
2,443
0.453
Medium
33,491
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708143/Python3-Simple-One-Line
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: for x in range(num+1): if x + int(str(x)[::-1]) == num: return True return False
sum-of-number-and-its-reverse
Python3, Simple One Line
Silvia42
0
19
sum of number and its reverse
2,443
0.453
Medium
33,492
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708117/Python-Easy-Solution
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: def reverse_digits(n): return int(str(n)[::-1]) for i in range(num + 1): if i == reverse_digits(num - i): return i, num - i return None
sum-of-number-and-its-reverse
Python - Easy Solution
blazers08
0
11
sum of number and its reverse
2,443
0.453
Medium
33,493
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708098/Easy-Python-Code-with-Comments-and-Methods
class Solution: def reverse_number(self, n): rev = 0 while n > 0: md = n % 10 rev = rev * 10 + md n = n // 10 return rev def sumOfNumberAndReverse(self, num: int) -> bool: if num == 0: return True n = len(str(num)) # don't go beyond n-2 length digits st = int(max(0, pow(10, n-2))) # start from num and go till last n-2 length digit for i in range(num, st, -1): rev = self.reverse_number(i) if rev + i == num: return True return False
sum-of-number-and-its-reverse
Easy Python Code with Comments and Methods
theanilbajar
0
15
sum of number and its reverse
2,443
0.453
Medium
33,494
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2708058/python-solution
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: def rev(s): n=str(s) n=n[::-1] return int(n) if num==0: return True for i in range(num): if i+rev(i)==num: return True return False
sum-of-number-and-its-reverse
python solution
shashank_2000
0
30
sum of number and its reverse
2,443
0.453
Medium
33,495
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2707993/Python3-One-Line
class Solution: def sumOfNumberAndReverse(self, total: int) -> bool: return any(num + int(str(num)[::-1]) == total for num in range(total // 2, total + 1))
sum-of-number-and-its-reverse
[Python3] One Line
0xRoxas
0
25
sum of number and its reverse
2,443
0.453
Medium
33,496
https://leetcode.com/problems/sum-of-number-and-its-reverse/discuss/2707993/Python3-One-Line
class Solution: def sumOfNumberAndReverse(self, total: int) -> bool: for num in range(total // 2, total + 1): if num + int(str(num)[::-1]) == total: return True return False
sum-of-number-and-its-reverse
[Python3] One Line
0xRoxas
0
25
sum of number and its reverse
2,443
0.453
Medium
33,497
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2708034/Python3-Sliding-Window-O(N)-with-Explanations
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: if minK > maxK: return 0 def count(l, r): if l + 1 == r: return 0 dic = Counter([nums[l]]) ans, j = 0, l + 1 for i in range(l + 1, r): dic[nums[i - 1]] -= 1 while not dic[minK] * dic[maxK] and j < r: dic[nums[j]] += 1 j += 1 if dic[minK] * dic[maxK]: ans += r - j + 1 else: break return ans arr = [-1] + [i for i, num in enumerate(nums) if num < minK or num > maxK] + [len(nums)] return sum(count(arr[i - 1], arr[i]) for i in range(1, len(arr)))
count-subarrays-with-fixed-bounds
[Python3] Sliding Window O(N) with Explanations
xil899
1
97
count subarrays with fixed bounds
2,444
0.432
Hard
33,498
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2717943/Python-Easy-Sweep-Line-sort-of-Solution
class Solution: # Travel from left to right and if you find minK assing p1 to it and when you find maxK assing p2 to it # When you find p1 and p2 both with valid numbers in between all the numbers left of p1 which are valid # will be added to the answer. As you keep travelling right keep adding all the valid numbers from the left of p1 # as those all will contribute to the answer! Hence wew need a variable to store leftmost id of valid number. def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: res = 0 p1 = p2 = left = -1 for right in range(len(nums)): if nums[right] == minK: p1 = right if nums[right] == maxK: p2 = right if nums[right] < minK or nums[right] > maxK: left = right res += max(0, (min(p1, p2) - left)) return res
count-subarrays-with-fixed-bounds
Python Easy Sweep Line sort of Solution
shiv-codes
0
22
count subarrays with fixed bounds
2,444
0.432
Hard
33,499