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/integer-to-roman/discuss/1184992/Python3-simple-and-easy-to-understand-solution-using-dictionary
class Solution: def intToRoman(self, num: int) -> str: d = {1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I'} s = '' for i in d.keys(): s += (num//i)*d[i] num %= i return s
integer-to-roman
Python3 simple and easy to understand solution using dictionary
EklavyaJoshi
6
328
integer to roman
12
0.615
Medium
500
https://leetcode.com/problems/integer-to-roman/discuss/1103010/Clean-and-Correct-Python-Solution
class Solution: def intToRoman(self, num: int) -> str: vals = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] romans = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ] res='' for i,v in enumerate(vals): ...
integer-to-roman
Clean & Correct Python Solution
lokeshsenthilkumar
6
623
integer to roman
12
0.615
Medium
501
https://leetcode.com/problems/integer-to-roman/discuss/1793052/Python-3-greater-Simple-solution-with-key-learnings
class Solution: def intToRoman(self, num: int) -> str: sym = { 1 : "I", 4 : "IV", 5 : "V", 9 : "IX", 10 : "X", 40 : "XL", 50 : "L", 90 : "XC", 100 : "C", 400 : "CD", ...
integer-to-roman
Python 3 -> Simple solution with key learnings
mybuddy29
5
282
integer to roman
12
0.615
Medium
502
https://leetcode.com/problems/integer-to-roman/discuss/2324305/Simple-greedy-solution-with-dictionary
class Solution: def intToRoman(self, num: int) -> str: values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] numerals = {1000 : 'M', 900 : 'CM', 500 : 'D', 400 : 'CD', 100 : 'C', 90 : 'XC', 50 : 'L', 40 : 'XL', 10 : 'X', 9 : 'IX', 5 : 'V', 4: 'IV', 1: 'I'} res ...
integer-to-roman
Simple greedy solution with dictionary
mfarrill
4
250
integer to roman
12
0.615
Medium
503
https://leetcode.com/problems/integer-to-roman/discuss/1801264/Python3-Straightforward-solution
class Solution: def intToRoman(self, num: int) -> str: roman = 'M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I'.split(',') integers = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] d=dict(zip(integers, roman )) res='' for n in integers: res += d[n]*(num//n) ...
integer-to-roman
[Python3] Straightforward solution
__PiYush__
4
194
integer to roman
12
0.615
Medium
504
https://leetcode.com/problems/integer-to-roman/discuss/1549409/Simple-Python-Solution-40-ms-faster-than-96.41-of-Python3-online-submissions.
class Solution: def intToRoman(self, num: int) -> str: dct = {1: 'I', 4: 'IV', 5: 'V', 9: 'IX', 10: 'X', 40: 'XL', 50: 'L', 90: 'XC', 100: 'C', 400: 'CD', 500: 'D', 900: 'CM', 1000: 'M'} stack = list(dct.keys()) ans = "" while num > 0: if stack[-1] > num: ...
integer-to-roman
Simple Python Solution 40 ms, faster than 96.41% of Python3 online submissions.
kunalraut335
4
271
integer to roman
12
0.615
Medium
505
https://leetcode.com/problems/integer-to-roman/discuss/2552032/Python-runtime-O(1)-memory-O(1)
class Solution: def intToRoman(self, num: int) -> str: ans = "" digits = [(1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), \ (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), \ (5, "V"), (4, "IV"), (1, "I")] i = 0 while i < len...
integer-to-roman
Python, runtime O(1), memory O(1)
tsai00150
3
339
integer to roman
12
0.615
Medium
506
https://leetcode.com/problems/integer-to-roman/discuss/2290902/Python-oror-Straight-Forward
class Solution: def intToRoman(self, num: int) -> str: rome = { 1: 'I', 5: 'V', 4: 'IV', 10: 'X', 9: 'IX', 50: 'L', 40: 'XL', 100: 'C', 90: 'XC', 500: 'D', 400: 'CD', 1000: 'M', 900: 'CM' } R = '' for i in range(3,-1,-1): conv = num//(10**i) if 0 < conv < 4: for k in range(conv): R += rome[10**i]...
integer-to-roman
Python || Straight Forward
morpheusdurden
3
168
integer to roman
12
0.615
Medium
507
https://leetcode.com/problems/integer-to-roman/discuss/1804259/99-Time-93-Memory-easy-to-understand-python-solution
class Solution: def intToRoman(self, num: int) -> str: ans = "" ans += "M"*(num//1000) ans += "D"*(num%1000//500) ans += "C"*(num%500//100) ans += "L"*(num%100//50) ans += "X"*(num%50//10) ans += "V"*(num%10//5) ans += "I"*(num%5) ans = ans.rep...
integer-to-roman
99% Time, 93% Memory, easy to understand python solution
user5901e
3
220
integer to roman
12
0.615
Medium
508
https://leetcode.com/problems/integer-to-roman/discuss/979027/Python-simple-solution
class Solution: def intToRoman(self, num: int) -> str: rules = ( ("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90), ("L", 50), ("XL", 40), ("XXX", 30), ("XX",...
integer-to-roman
Python simple solution
yuliy
3
354
integer to roman
12
0.615
Medium
509
https://leetcode.com/problems/integer-to-roman/discuss/264463/Simple-Solution-with-python3-76ms
class Solution: def intToRoman(self, num: int) -> str: t = '' for i in X: tmp = num // i if tmp > 0: t += X[i] * tmp num -= (tmp * i) return t X = { 1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC'...
integer-to-roman
Simple Solution with python3 76ms
Conight
3
144
integer to roman
12
0.615
Medium
510
https://leetcode.com/problems/integer-to-roman/discuss/2726348/easy-understandble-python-code-with-good-runtime
class Solution: def intToRoman(self, num: int) -> str: values = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] numerals = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ] res="" for i,v in enumerate(values): res+=(num//v)*numerals[i] ...
integer-to-roman
easy understandble python code with good runtime
V_Bhavani_Prasad
2
47
integer to roman
12
0.615
Medium
511
https://leetcode.com/problems/integer-to-roman/discuss/2366605/Python-Elegant-and-Short-or-99.89-faster
class Solution: """ Time: O(1) Memory: O(1) """ ROMAN_TO_INTEGER = { 'M': 1000, 'CM': 900, 'D': 500, 'CD': 400, 'C': 100, 'XC': 90, 'L': 50, 'XL': 40, 'X': 10, 'IX': 9, 'V': 5, 'IV': 4, 'I': 1, } def intToRoman(self, num: int) -> str: converted = '' for roman, integer in...
integer-to-roman
Python Elegant & Short | 99.89% faster
Kyrylo-Ktl
2
95
integer to roman
12
0.615
Medium
512
https://leetcode.com/problems/integer-to-roman/discuss/2238167/Basic-Python-Solution-(53-ms)
class Solution: def intToRoman(self, num: int) -> str: roman ={1 :'I', 4 : 'IV', 5 : 'V', 9 : 'IX', 10 : 'X', 40 : 'XL', 50 : 'L', 90 : 'XC', 100 : 'C', 400 : 'C...
integer-to-roman
Basic Python Solution (53 ms)
mayank9
2
191
integer to roman
12
0.615
Medium
513
https://leetcode.com/problems/integer-to-roman/discuss/2165509/Python-beats-90-with-full-working-explanation
class Solution: def intToRoman(self, num: int) -> str: # Time: O(n) and Space: O(1) symbolList = [['I', 1], ['IV', 4], ['V', 5], ['IX', 9], ['X', 10], ['XL', 40], ['L', 50], ['XC', 90], ['C', 100], ['CD', 400], ['D', 500], ['CM', 900], ['M...
integer-to-roman
Python beats 90% with full working explanation
DanishKhanbx
2
244
integer to roman
12
0.615
Medium
514
https://leetcode.com/problems/integer-to-roman/discuss/1949975/Python-simple-solution
class Solution: def intToRoman(self, num: int) -> str: hashmap = {1: 'I', 4: 'IV', 5: 'V', 9: 'IX', 10: 'X', 40: 'XL', 50: 'L', 90: 'XC', 100: 'C', 400: 'CD', 500: 'D', 900: 'CM', 1000: 'M'} sol = "" while num > 0: for n in reversed(hashmap): if num >= n: ...
integer-to-roman
Python simple solution
alessiogatto
2
180
integer to roman
12
0.615
Medium
515
https://leetcode.com/problems/integer-to-roman/discuss/1731380/Python-3-Making-use-of-the-built-in-divmod-function-(56ms-13.8MB)
class Solution: def intToRoman(self, num: int) -> str: mapping = [(1000, 'M'), (900, 'CM'), (500, 'D'), \ (400, 'CD'), (100, 'C'), (90, 'XC'), \ (50, 'L'), (40, 'XL'), (10, 'X'), \ (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')] answer = '' ...
integer-to-roman
[Python 3] Making use of the built-in `divmod` function (56ms, 13.8MB)
seankala
2
118
integer to roman
12
0.615
Medium
516
https://leetcode.com/problems/integer-to-roman/discuss/1222011/Python3-98-faster-84-memory
class Solution: def intToRoman(self, num: int) -> str: letters = {1: 'I', 5: 'V', 10: 'X', 50: 'L', 100: 'C', 500: 'D', 1000: 'M'} i = 1 roman="" while num != 0: digit = num % 10 if digit==1 or digit==5: roman=letters[digit*i]+roman ...
integer-to-roman
Python3 98% faster 84% memory
nikhilchaudhary0126
2
121
integer to roman
12
0.615
Medium
517
https://leetcode.com/problems/integer-to-roman/discuss/1068027/simple-easy-to-understand-python3-solution
class Solution: def intToRoman(self, num: int) -> str: number = [1000,900,500,400,100,90,50,40,10,9,5,4,1] roman_symbol = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I'] roman_string = "" for index, value in enumerate(number): quotient = num // value ...
integer-to-roman
simple, easy to understand python3 solution
headoftheport1230
2
128
integer to roman
12
0.615
Medium
518
https://leetcode.com/problems/integer-to-roman/discuss/2724560/C%2B%2B-Go-Python-TypeScript-JavaScript-simple-approach
class Solution: def intToRoman(self, n: int) -> str: r = '' while True: print(n) if n - 1000 > -1: r += 'M' n -= 1000 elif n - 900 > -1: r += 'CM' n -= 900 elif n - 500 > -1: ...
integer-to-roman
C++ / Go / Python / TypeScript / JavaScript simple approach
nuoxoxo
1
89
integer to roman
12
0.615
Medium
519
https://leetcode.com/problems/integer-to-roman/discuss/2724164/FASTEST-AND-EASIEST-oror-FASTER-THAN-95-SUBMISSIONS-oror-MAPPING
class Solution: def intToRoman(self, num: int) -> str: mp=[(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V'),...
integer-to-roman
FASTEST AND EASIEST || FASTER THAN 95% SUBMISSIONS || MAPPING
Pritz10
1
11
integer to roman
12
0.615
Medium
520
https://leetcode.com/problems/integer-to-roman/discuss/2305037/Python-Effective-Solution
class Solution: def intToRoman(self, num: int) -> str: dic_roman = { 1:['I','V'], 2:['X','L'], 3:['C','D'], 4:['M'] } list1 = [int(i) for i in str(num)] num_lenl = len(list1) res = '' for i in list1: ...
integer-to-roman
Python Effective Solution
zip_demons
1
99
integer to roman
12
0.615
Medium
521
https://leetcode.com/problems/integer-to-roman/discuss/2208701/Easy-solution-to-understand-using-a-Dictionary
class Solution: def intToRoman(self, num: int) -> str: # Make a dictionry for all possible integers including exceptions dic={1:'I',4:'IV',5:'V',9:'IX',10:'X',40:'XL',50:'L',90:'XC',100:'C',400:'CD',500:'D',900:'CM',1000:'M'} # create a sorted array to store the keys just t...
integer-to-roman
Easy solution to understand using a Dictionary
shubham_mishra204
1
168
integer to roman
12
0.615
Medium
522
https://leetcode.com/problems/integer-to-roman/discuss/2180150/Simple-Python-Solution-(Beats-100-python3-submission)-(16-ms)
class Solution: def intToRoman(self, nums: int) -> str: s="" thousands=nums//1000 if(thousands>0): s+="M"*thousands nums-=1000*thousands hundreds=nums//100 if(hundreds>0): if(hundreds==5): s+="D" elif(hundreds==9...
integer-to-roman
Simple Python Solution (Beats 100% python3 submission) (16 ms)
ravishk17
1
130
integer to roman
12
0.615
Medium
523
https://leetcode.com/problems/integer-to-roman/discuss/2066622/Simple-solution-Python
class Solution: def intToRoman(self, num: int) -> str: def san(n, x1, x2, x3): #print('san') san = '' if n == 9: san = x1 + x3 elif n == 4: san = x1 + x2 else: if n >= 5: san += x2...
integer-to-roman
Simple solution Python
Adaisky
1
179
integer to roman
12
0.615
Medium
524
https://leetcode.com/problems/integer-to-roman/discuss/1947770/Python3-Simple-While-Loops-Solution-(faster-than-94)
class Solution: def intToRoman(self, num: int) -> str: # Using While Loops to Add to a String :) string = "" while num >= 1000: string += "M" num -= 1000 while num >= 900: string += "CM" num -= 900 whi...
integer-to-roman
[Python3] Simple While Loops Solution (faster than 94%)
Rustizx
1
74
integer to roman
12
0.615
Medium
525
https://leetcode.com/problems/integer-to-roman/discuss/1899198/Python-Simple-solution-explained
class Solution: def intToRoman(self, num: int) -> str: # we'll maintain the usual mapping but # also the "one-less" value mapping. why? # because the way we've written our solution # if we didn't have the mapping the way we do # the output for num=900, would actually...
integer-to-roman
[Python] Simple solution explained
buccatini
1
225
integer to roman
12
0.615
Medium
526
https://leetcode.com/problems/integer-to-roman/discuss/1698363/Super-simple-Python-solution-with-runtime%3A-44-ms-faster-than-90.64-submissions
class Solution: def intToRoman(self, num: int) -> str: weights = [ (1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), ...
integer-to-roman
Super simple Python solution with runtime: 44 ms, faster than 90.64% submissions
bodanish
1
140
integer to roman
12
0.615
Medium
527
https://leetcode.com/problems/integer-to-roman/discuss/1670455/Simple-and-short-python-solution-(40ms)
class Solution: def intToRoman(self, num: int) -> str: rom_dig = '' pre = {0: '', 1: 'I', 5:'V', 10:'X', 50:'L', 100:'C', 500:'D', 1000:'M'} place = 1 while num: dig = num%10 if (dig+1)%5==0: rom_dig = pre[place]+pre[(dig+...
integer-to-roman
Simple and short python solution (40ms)
Charging-to-100
1
107
integer to roman
12
0.615
Medium
528
https://leetcode.com/problems/integer-to-roman/discuss/1662193/Python-Greedy-solution-easy-to-understand
class Solution: def intToRoman(self, num: int) -> str: arr1 = [1,4,5,9,10,40,50,90,100,400,500,900,1000] arr2 = ['I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M'] n = num i = len(arr1)-1 st = '' while n != 0 and i>=0: if n - arr1[i] >= 0: ...
integer-to-roman
Python Greedy solution, easy to understand
myp001
1
265
integer to roman
12
0.615
Medium
529
https://leetcode.com/problems/integer-to-roman/discuss/1411410/Python-Simple-O(1)O(1)-Faster-Than-87
class Solution: def intToRoman(self, num: int) -> str: translator = {1: 'I', 5: 'V', 10: 'X', 50: 'L', 100: 'C', 500: 'D', 1000: 'M', 4: 'IV', 9: 'IX', 40: 'XL', 90: 'XC', 400: 'CD', 900: 'CM'} roman = '' for i in sorted(translator.keys(), reverse=True): ...
integer-to-roman
Python Simple O(1)/O(1) Faster Than 87%
Medium_Conversation
1
371
integer to roman
12
0.615
Medium
530
https://leetcode.com/problems/integer-to-roman/discuss/1344349/Faster-than-99.64-python-solution
class Solution: def intToRoman(self, num: int) -> str: def romanHelper(upper, middle, lower, factor): if factor == 9: return lower + upper elif factor >= 5: return middle + lower*(factor%5) elif factor == 4: return lower + m...
integer-to-roman
Faster than 99.64% python solution
MrAlpha786
1
408
integer to roman
12
0.615
Medium
531
https://leetcode.com/problems/integer-to-roman/discuss/653558/Python3-modulo-operation
class Solution: def intToRoman(self, num: int) -> str: mp = {1000:"M", 900:"CM", 500:"D", 400:"CD", 100:"C", 90:"XC", 50:"L", 40:"XL", 10:"X", 9:"IX", 5:"V", 4:"IV", 1:"I"} ans = [] for k, v in mp.items(): ans.append(num//k * v) num %= k return "".join(ans)
integer-to-roman
[Python3] modulo operation
ye15
1
127
integer to roman
12
0.615
Medium
532
https://leetcode.com/problems/integer-to-roman/discuss/653558/Python3-modulo-operation
class Solution: def intToRoman(self, num: int) -> str: mp = {1:"I", 5:"V", 10:"X", 50:"L", 100:"C", 500:"D", 1000:"M"} ans = [] m = 1 while num: num, x = divmod(num, 10) if x == 9: ans.append(mp[m] + mp[10*m]) elif x == 4: ans.append(mp[m...
integer-to-roman
[Python3] modulo operation
ye15
1
127
integer to roman
12
0.615
Medium
533
https://leetcode.com/problems/integer-to-roman/discuss/2847421/Python-best-solution
class Solution: def intToRoman(self, num: int) -> str: final_str = "" roman_map = { 1: "I", 4: "IV", 5: "V", 9: "IX", 10: "X", 40: "XL", 50: "L", 90: "XC", 100: "C", 400: "CD", ...
integer-to-roman
Python best solution
Nihshreyas
0
2
integer to roman
12
0.615
Medium
534
https://leetcode.com/problems/integer-to-roman/discuss/2844956/Only-5-cases-easy-to-understand-whit-explanation
class Solution: def intToRoman(self, num: int) -> str: # Saving the digists in the list, but we must note here, # that this digits are saving as string. num = list(str(num)) # Dictionary: roman_number = { 1000 : "M", 500 : "D", ...
integer-to-roman
Only 5 cases, easy to understand whit explanation
hafid-hub
0
1
integer to roman
12
0.615
Medium
535
https://leetcode.com/problems/integer-to-roman/discuss/2833911/Python-simple-and-easy-to-understand-solution
class Solution: def intToRoman(self, num: int) -> str: d = { 1 : 'I', 4: 'IV', 5 : 'V', 9: 'IX', 10 : 'X', 40: 'XL', 50 : 'L', 90: 'XC', 100: 'C', 400: 'CD', 500: 'D', 900: 'CM', 1000: 'M' } roman = '' for n in...
integer-to-roman
Python simple and easy to understand solution
Sudhanshu344
0
2
integer to roman
12
0.615
Medium
536
https://leetcode.com/problems/integer-to-roman/discuss/2828597/Low-Memory-Solution-(Python3)
class Solution: def intToRoman(self, num: int) -> str: roman = [ [1000,'M'], [900,'CM'], [500,'D'], [400,'CD'], [100,'C'], [90,'XC'], [50,'L'], [40,'XL'], [10,'X'], [9,'IX'], [...
integer-to-roman
Low Memory Solution (Python3)
smithshannonf
0
3
integer to roman
12
0.615
Medium
537
https://leetcode.com/problems/integer-to-roman/discuss/2827225/Reduce-based-Solution-The-Best
class Solution: def intToRoman(self, num: int) -> str: SYMBOLS = 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' VALUES = 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 rom = '' for numeral, divisor in zip(SYMBOLS, VALUES): ...
integer-to-roman
Reduce-based Solution, The Best
Triquetra
0
3
integer to roman
12
0.615
Medium
538
https://leetcode.com/problems/integer-to-roman/discuss/2827225/Reduce-based-Solution-The-Best
class Solution: def intToRoman(self, num: int) -> str: SYMBOLS = 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' VALUES = 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 return reduce(self.produceSymbols, zip(SYMBOLS, VALUES), (num, ''))[1] ...
integer-to-roman
Reduce-based Solution, The Best
Triquetra
0
3
integer to roman
12
0.615
Medium
539
https://leetcode.com/problems/integer-to-roman/discuss/2801102/Easy-Understanding
class Solution: def intToRoman(self, num: int) -> str: result = "" if num // 1000 != 0: result += "M" * (num // 1000) num %= 1000 if num // 900 == 1: result += "CM" num %= 900 if num // 500 == 1: result += "D" nu...
integer-to-roman
Easy Understanding
eugen3ee
0
6
integer to roman
12
0.615
Medium
540
https://leetcode.com/problems/integer-to-roman/discuss/2799652/Python3-98.38-runtime-and-80.24-memory-beats-solution!!!!
class Solution: def intToRoman(self, num: int) -> str: a = num // 1000 b = (num - 1000 * a) // 100 c = (num - 1000 * a - 100 * b) // 10 d = num - 1000 * a - 100 * b - 10 * c """ N is int number from 0 to 9. X coresppond to I. Y coresppond to V. ...
integer-to-roman
[Python3] 98.38% runtime & 80.24 % memory beats solution!!!!
jungledowmtown55
0
10
integer to roman
12
0.615
Medium
541
https://leetcode.com/problems/integer-to-roman/discuss/2798606/Python-code-using-recursive-function
class Solution: def intToRoman(self, num: int) -> str: if num >= 1000: return "M" + self.intToRoman(num-1000) elif num >= 900: return "CM" + self.intToRoman(num-900) elif num >= 500: return "D" + self.intToRoman(num-500) elif num >= 400: ...
integer-to-roman
Python code using recursive function
derbuihan
0
2
integer to roman
12
0.615
Medium
542
https://leetcode.com/problems/integer-to-roman/discuss/2792586/Easiest-Python-Solution
class Solution: def intToRoman(self, num: int) -> str: roman = "" values = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] numerals = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ] for index, value in enumerate(values): roman += (num//...
integer-to-roman
Easiest Python Solution
sachinsingh31
0
4
integer to roman
12
0.615
Medium
543
https://leetcode.com/problems/integer-to-roman/discuss/2779448/Integer-To-Roman
class Solution: def intToRoman(self, num: int) -> str: roman = {"I" : 1, "IV":4, "V": 5, "IX":9, "X": 10, "XL":40, "L": 50, "XC":90, "C": 100, "CD":400, "D": 500, "CM":900, "M": 1000} result = "" for key, val in reversed(roman.items()): if num // val: ...
integer-to-roman
Integer To Roman
Hamideddie
0
7
integer to roman
12
0.615
Medium
544
https://leetcode.com/problems/integer-to-roman/discuss/2776887/Simplest-Approach-Space-Saving-Easy-To-Understand-Brute-Force-%3A-Python
class Solution: def intToRoman(self, num: int) -> str: out="" while(num>0): if num>=1 and num<5: if num>=4: num=num-4 out=out+"IV" else: num=num-1 out=out+"I" if nu...
integer-to-roman
Simplest Approach Space Saving Easy To Understand Brute Force : Python
hritikbatra
0
2
integer to roman
12
0.615
Medium
545
https://leetcode.com/problems/integer-to-roman/discuss/2764367/python-easy-solution
class Solution: def intToRoman(self, num: int) -> str: if num==0:return '' if num>=1000: return 'M' + self.intToRoman(num-1000) if num>=900: return 'CM'+self.intToRoman(num-900) if num>=500: return 'D' + self.intToRoman(num-500) if num>=400: return 'CD'+self.intToRoman(num-40...
integer-to-roman
python easy solution
tush18
0
9
integer to roman
12
0.615
Medium
546
https://leetcode.com/problems/integer-to-roman/discuss/2757693/Python-Deque
class Solution: def intToRoman(self, num: int) -> str: """ Symbol Value I 1 ones V 5 ones X 10 tens L 50 tens C 100 hundreds D 500 hundreds M ...
integer-to-roman
Python Deque
ckayfok
0
6
integer to roman
12
0.615
Medium
547
https://leetcode.com/problems/roman-to-integer/discuss/264743/Clean-Python-beats-99.78.
class Solution: def romanToInt(self, s: str) -> int: translations = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000 } number = 0 s = s.replace("IV", "IIII").replace("IX", "VIIII") ...
roman-to-integer
Clean Python, beats 99.78%.
hgrsd
1,200
60,900
roman to integer
13
0.582
Easy
548
https://leetcode.com/problems/roman-to-integer/discuss/2428756/Python-oror-Easily-Understood-oror-Faster-than-98-oror-Less-than-76-oror-O(n)
class Solution: def romanToInt(self, s: str) -> int: roman_to_integer = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000, } s = s.replace("IV", "IIII").replace("IX", "VIIII").replace("XL", "X...
roman-to-integer
🔥 Python || Easily Understood ✅ || Faster than 98% || Less than 76% || O(n)
wingskh
146
15,300
roman to integer
13
0.582
Easy
549
https://leetcode.com/problems/roman-to-integer/discuss/1791875/Python-3-greater-Simple-and-detailed-explanation
class Solution: def romanToInt(self, s: str) -> int: sym = { "I" : 1, "V" : 5, "X" : 10, "L" : 50, "C" : 100, "D" : 500, "M" : 1000 } result = 0 prev = 0 for c in reversed(s)...
roman-to-integer
Python 3 -> Simple and detailed explanation
mybuddy29
44
1,500
roman to integer
13
0.582
Easy
550
https://leetcode.com/problems/roman-to-integer/discuss/1941583/Python-3-solution-less-than-98-Memory-Usage-with-explanation.
class Solution: def romanToInt(self, s: str) -> int: mapping = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, "IV": -2, "IX": -2, "XL": -20, "XC": -20, ...
roman-to-integer
Python 3 solution less than 98% Memory Usage with explanation.
wabesasa
33
1,500
roman to integer
13
0.582
Easy
551
https://leetcode.com/problems/roman-to-integer/discuss/357734/Python-Solution-with-explanantion
class Solution: def romanToInt(self, s: str) -> int: roman_to_int = { 'I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000 } result = 0 prev_value = 0 for letter in ...
roman-to-integer
Python Solution with explanantion
amchoukir
29
3,700
roman to integer
13
0.582
Easy
552
https://leetcode.com/problems/roman-to-integer/discuss/2272944/PYTHON-3-BEATS-99.13-or-EASY-TO-UNDERSTAND
class Solution: def romanToInt(self, s: str) -> int: a, r = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, "IV": -2, "IX": -2, "XL": -20, "XC": -20, "CD": -200, "CM": -200}, 0 for d, e in a.items(): r += s.count(d) * e return r
roman-to-integer
[PYTHON 3] BEATS 99.13% | EASY TO UNDERSTAND
omkarxpatel
20
1,600
roman to integer
13
0.582
Easy
553
https://leetcode.com/problems/roman-to-integer/discuss/2372626/Clean-efficient-and-easy-to-read-Python-beats-99.5.
class Solution: def romanToInt(self, s: str) -> int: ''' faster solution which doesn't require iterating through every element of s (currently faster than 99.49% of submissions''' # store all possible conversions roman_conversion = {"IV": 4, "IX": 9, "XL": 40, "XC": 90, "CD": 400, "CM": 900...
roman-to-integer
Clean, efficient, and easy-to-read Python, beats 99.5%.
romejj
14
937
roman to integer
13
0.582
Easy
554
https://leetcode.com/problems/roman-to-integer/discuss/2021425/Python-Solution
class Solution: def romanToInt(self, s: str) -> int: roman = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} res = 0 for i in range(len(s)): if i+1 < len(s) and roman[s[i]] < roman[s[i+1]]: res -= roman[s[i]] else: ...
roman-to-integer
Python Solution
afreenansari25
13
915
roman to integer
13
0.582
Easy
555
https://leetcode.com/problems/roman-to-integer/discuss/1140243/Python-solution-(48ms-14.3MB)-using-a-reversed-string.
class Solution: def romanToInt(self, s: str) -> int: dic = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} res, tmp = 0, 0 for i in reversed(s): if dic[i]>=tmp: res=res+dic[i] else: res=res-dic[i] tmp=dic[i...
roman-to-integer
Python solution (48ms 14.3MB) - using a reversed string.
kritikaasri
13
983
roman to integer
13
0.582
Easy
556
https://leetcode.com/problems/roman-to-integer/discuss/2669258/Python-solution-with-hashmap
class Solution: def romanToInt(self, s: str) -> int: alphabet = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000, } dec_number = 0 last_add = 0 for ch in s[::-1]: ...
roman-to-integer
✔️ Python solution with hashmap
QuiShimo
12
1,100
roman to integer
13
0.582
Easy
557
https://leetcode.com/problems/roman-to-integer/discuss/1298123/Python3-Super-fast-than-99
class Solution: def romanToInt(self, s: str) -> int: letters = list(s) romans = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} sum_let = 0 prev = None for lets in letters: if prev is not None and romans[prev] < romans[lets]: sum_let+=(...
roman-to-integer
Python3 Super fast than 99%
mishra_g
12
1,600
roman to integer
13
0.582
Easy
558
https://leetcode.com/problems/roman-to-integer/discuss/484638/Python-3-(one-line)
class Solution: def romanToInt(self, S: str) -> int: return sum(S.count(r)*v for r,v in [('I',1),('V',5),('X',10),('L',50),('C',100),('D',500),('M',1000),('IV',-2),('IX',-2),('XL',-20),('XC',-20),('CD',-200),('CM',-200)]) - Junaid Mansuri - Chicago, IL
roman-to-integer
Python 3 (one line)
junaidmansuri
9
1,400
roman to integer
13
0.582
Easy
559
https://leetcode.com/problems/roman-to-integer/discuss/2479970/python3-or-fast-or-space-O(1)-or-time-O(n)
class Solution: def romanToInt(self, s: str) -> int: a={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000} sum=0 x=0 while x<len(s): if x<len(s)-1 and a[s[x]]<a[s[x+1]]: sum += (a[s[x+1]] - a[s[x]]) x += 2 else: ...
roman-to-integer
python3 | fast | space-O(1) | time - O(n)
I_am_SOURAV
8
705
roman to integer
13
0.582
Easy
560
https://leetcode.com/problems/roman-to-integer/discuss/2689932/EASY-PYTHON-SOLUTION
class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ roman_dic = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, } skip_...
roman-to-integer
EASY PYTHON SOLUTION
raghavdabra
7
2,600
roman to integer
13
0.582
Easy
561
https://leetcode.com/problems/roman-to-integer/discuss/1628386/Faster-than-99-and-with-hash-table.
class Solution: def romanToInt(self, s: str) -> int: map_ = {"I":1 ,"V":5, "X":10, "L":50, "C":100, "D":500, "M":1000} val = 0 i = len(s)-1 while i >= 0: if map_[s[i]] > map_[s[i-1]] and i != 0: val += (map_[s[i]]-map_[s[i-1]]) i -...
roman-to-integer
Faster than 99% and with hash table.
AmrinderKaur1
7
811
roman to integer
13
0.582
Easy
562
https://leetcode.com/problems/roman-to-integer/discuss/2595959/Roman-to-Integer-oror-Python3-oror-Easy
class Solution: def romanToInt(self, s: str) -> int: roman_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} value = 0 for i in range(0, len(s)-1): # If we have low value char before higher value then it should be subtracted ...
roman-to-integer
Roman to Integer || Python3 || Easy
vanshika_2507
5
370
roman to integer
13
0.582
Easy
563
https://leetcode.com/problems/roman-to-integer/discuss/2427959/Python-Elegant-and-Short-or-93.51-faster-or-Constant-time-and-memory
class Solution: """ Time: O(1) Memory: O(1) """ ROMAN_TO_INTEGER = { 'I': 1, 'IV': 4, 'V': 5, 'IX': 9, 'X': 10, 'XL': 40, 'L': 50, 'XC': 90, 'C': 100, 'CD': 400, 'D': 500, 'CM': 900, 'M': 1000, } def romanToInt(self, s: str) -> int: converted = 0 for roman, integer in se...
roman-to-integer
Python Elegant & Short | 93.51% faster | Constant time and memory
Kyrylo-Ktl
5
404
roman to integer
13
0.582
Easy
564
https://leetcode.com/problems/roman-to-integer/discuss/1524835/Python-Solution-with-'subtraction'-idea
class Solution: def romanToInt(self, s: str) -> int: dict_normal = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} dict_subtract = {'IV': 1, 'IX': 1, 'XL': 10, 'XC': 10, 'CD': 100, 'CM': 100} sum_all = sum([dict_normal[s_letter] for s_letter in list(s)]) sum_deduct = sum([dict_subtract[subtra...
roman-to-integer
Python Solution with 'subtraction' idea
xxhowchanxx
5
445
roman to integer
13
0.582
Easy
565
https://leetcode.com/problems/roman-to-integer/discuss/1409296/Python-3-Simple-code-using-dictionary
class Solution: def romanToInt(self, roman: str) -> int: convert = {'IV':'IIII', 'IX':'VIIII', 'XL':'XXXX', 'XC':'LXXXX', 'CD':'CCCC', 'CM':'DCCCC'} roman_units = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1} for key in convert.keys(): if key in roman: ...
roman-to-integer
[Python 3] Simple code using dictionary
shreyamittal117
5
281
roman to integer
13
0.582
Easy
566
https://leetcode.com/problems/roman-to-integer/discuss/246482/Creative-no-dictionary-Python-Solution
class Solution: def romanToInt(self, s: str) -> int: sym = 'IVXLCDM' val = [1,5,10,50,100,500,1000] highest, res = 0, 0 for i in s[::-1]: ix = sym.index(i) if ix >= highest: res += val[ix] highest = ix else: ...
roman-to-integer
Creative no-dictionary Python Solution
leetro
5
794
roman to integer
13
0.582
Easy
567
https://leetcode.com/problems/roman-to-integer/discuss/2690026/Python-Simple-O(n)-Solution-with-full-working-explanation
class Solution: # Time: O(n) and Space: O(1) def romanToInt(self, s: str) -> int: # From Smallest Roman value to Biggest. roman = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 } ...
roman-to-integer
Python Simple O(n) Solution with full working explanation
DanishKhanbx
4
672
roman to integer
13
0.582
Easy
568
https://leetcode.com/problems/roman-to-integer/discuss/2304864/Easy-Python-Solution-Using-Dictionary
class Solution: def romanToInt(self, s: str) -> int: roman_dict = { "I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000 } ans = roman_dict[s[-1]] for i in range(len(s)-1): ...
roman-to-integer
Easy Python Solution Using Dictionary
zip_demons
4
483
roman to integer
13
0.582
Easy
569
https://leetcode.com/problems/roman-to-integer/discuss/2006278/Simple-Python-solution
class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ d = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} num = 0 for i in range(len(s)-1): # If the next letter has larger value than the current, the current l...
roman-to-integer
Simple Python solution
rafaelcuperman
4
307
roman to integer
13
0.582
Easy
570
https://leetcode.com/problems/roman-to-integer/discuss/1865456/Easy-to-understand-Python-solution
class Solution: def romanToInt(self, s: str) -> int: convertedInt = 0 romanHashmap = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, } prevChar = None for i in range(0, len(...
roman-to-integer
Easy to understand Python solution
deepjaisia
4
598
roman to integer
13
0.582
Easy
571
https://leetcode.com/problems/roman-to-integer/discuss/1781818/2-dictionaries-2-loops.-logical.-O(N)
class Solution: def romanToInt(self, s: str) -> int: map={ "I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000, } total = 0 ex_map = { "IV":4, "IX":9, "XL":40,...
roman-to-integer
2 dictionaries 2 loops. logical. O(N)
_rn_
4
333
roman to integer
13
0.582
Easy
572
https://leetcode.com/problems/roman-to-integer/discuss/1670229/Logic-explained-in-detail.
class Solution: def romanToInt(self, s: str) -> int: lookup = { 'I':1, 'V': 5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000, } integer = 0 prev = cur = lookup[s[0]] for i in s[1:]: ...
roman-to-integer
Logic explained in detail.
souravrane_
4
222
roman to integer
13
0.582
Easy
573
https://leetcode.com/problems/roman-to-integer/discuss/1591120/Python3-Solution
class Solution: def romanToInt(self, s: str) -> int: d = {'I':1, 'V':5, 'X':10, 'L':50,'C':100,'D':500,'M':1000} number = 0 p = 0 for i in range(len(s)-1,-1,-1): if d[s[i]]>= p: number += d[s[i]] else: number -= d[s[i]] ...
roman-to-integer
Python3 Solution
light_1
4
152
roman to integer
13
0.582
Easy
574
https://leetcode.com/problems/roman-to-integer/discuss/1591120/Python3-Solution
class Solution: def romanToInt(self, s: str) -> int: number = 0 s = s.replace("IV", "IIII") s = s.replace("IX", "VIIII") s = s.replace("XL", "XXXX") s = s.replace("XC", "LXXXX") s = s.replace("CD", "CCCC") s = s.replace("CM", "DCCCC") for char in s: ...
roman-to-integer
Python3 Solution
light_1
4
152
roman to integer
13
0.582
Easy
575
https://leetcode.com/problems/roman-to-integer/discuss/1548697/EZ-Solution-or-PYTHON-or-97-97
class Solution: def romanToInt(self, s: str) -> int: symbolsValue = {'IV':4,'IX':9,'XL':40,'XC':90,'CD':400,'CM':900, 'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} res = 0 while s: for key, val in symbolsValue.items(): if key in s: ...
roman-to-integer
EZ Solution | PYTHON | 97% 97%
zoharfran
4
566
roman to integer
13
0.582
Easy
576
https://leetcode.com/problems/roman-to-integer/discuss/672937/Python-line-by-line-explanation
class Solution: def romanToInt(self, s: str) -> int: # use a dictionary to map the letters to values digits = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000} # set the year as the value of the last letter year = digits[s[len(s)-1]] # i is the index of the string, starting from the last...
roman-to-integer
Python line by line explanation
derekchia
4
346
roman to integer
13
0.582
Easy
577
https://leetcode.com/problems/roman-to-integer/discuss/652705/Python3-linear-scan
class Solution: def romanToInt(self, s: str) -> int: mp = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} ans = 0 for i in range(len(s)): if i+1 < len(s) and mp[s[i]] < mp[s[i+1]]: ans -= mp[s[i]] else: ans += mp[s[i]] return ans
roman-to-integer
[Python3] linear scan
ye15
4
247
roman to integer
13
0.582
Easy
578
https://leetcode.com/problems/roman-to-integer/discuss/652705/Python3-linear-scan
class Solution: def romanToInt(self, s: str) -> int: mp = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000, "IV":4, "IX":9, "XL":40, "XC":90, "CD":400, "CM":900} ans = i = 0 while i < len(s): if s[i:i+2] in mp: ans += mp[s[i:i+2]] ...
roman-to-integer
[Python3] linear scan
ye15
4
247
roman to integer
13
0.582
Easy
579
https://leetcode.com/problems/roman-to-integer/discuss/2161575/python-solution
class Solution: def romanToInt(self, s: str) -> int: d={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000} x=0 i=0 while i<len(s): if i+1<len(s): if d[s[i]]<d[s[i+1]]: x=x+d[s[i+1]]-d[s[i]] i=i+2 els...
roman-to-integer
python solution
komin521
3
448
roman to integer
13
0.582
Easy
580
https://leetcode.com/problems/roman-to-integer/discuss/2028400/Python3%3A-easy-looped-over
class Solution: def romanToInt(self, s: str) -> int: r = 0 m = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} for i, c in enumerate(s): if (i <= len(s)-2 and m[c] < m[s[i+1]]): r-=m[c] else: r+=m[c] return r
roman-to-integer
Python3: easy looped over
doesnotcompile
3
418
roman to integer
13
0.582
Easy
581
https://leetcode.com/problems/roman-to-integer/discuss/1811219/Python3-Sol-Faster-than-89.84
class Solution: def romanToInt(self, s: str) -> int: d = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} res = 0 for i in range(len(s)-1): if d[s[i]] < d[s[i+1]]: res = res - d[s[i]] else: res = res + d[s[i]] return r...
roman-to-integer
Python3 Sol - Faster than 89.84%
shivamm0296
3
318
roman to integer
13
0.582
Easy
582
https://leetcode.com/problems/roman-to-integer/discuss/1760354/Simple-Python-Solution
class Solution: def romanToInt(self, s: str) -> int: d={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000, 'IV':4,'IX':9,'XL':40,'XC':90,'CD':400,'CM':900} i,su=0,0 while i<len(s): if i+1<len(s) and s[i:i+2] in d: su+=d[s[i:i+2]] ...
roman-to-integer
Simple Python Solution
adityabaner
3
449
roman to integer
13
0.582
Easy
583
https://leetcode.com/problems/roman-to-integer/discuss/1371160/36-ms
class Solution: def romanToInt(self, s: str) -> int: hashmap = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} total, prev = 0, 0 for i in s: cur = hashmap[i] if cur > prev: total -= prev total += cur - prev ...
roman-to-integer
36 ms
Ojaas
3
168
roman to integer
13
0.582
Easy
584
https://leetcode.com/problems/roman-to-integer/discuss/2781564/python-solution-using-list-and-list-methods
class Solution: def romanToInt(self, s: str) -> int: sym=["I","V","X","L","C","D","M"] val=[1,5,10,50,100,500,1000] sum=0 l=len(s) flag=0 i=0 while i <l-1: fp=sym.index(s[i]) sp=sym.index(s[i+1]) if sp>fp: su...
roman-to-integer
python solution using list and list methods🔥
Yadunandan_1
2
607
roman to integer
13
0.582
Easy
585
https://leetcode.com/problems/roman-to-integer/discuss/2686088/Smooth-Python-3-solution-(greater98)
class Solution: def romanToInt(self, s: str) -> int: translation = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} l1 = [translation[i] for i in s] l1.reverse() num ...
roman-to-integer
Smooth Python 3 solution (>98%)
sskabarin
2
1,100
roman to integer
13
0.582
Easy
586
https://leetcode.com/problems/roman-to-integer/discuss/2426734/Python-Solution-with-Dictionary
class Solution: def romanToInt(self, s: str) -> int: d={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000,"IV":4,"IX":9,"XL":40,"XC":90,"CD":400,"CM":900} ans=0 i=0 while i<len(s): if s[i:i+2] in d: ans+=d[s[i:i+2]] i+=2 else: ...
roman-to-integer
Python Solution with Dictionary
a_dityamishra
2
272
roman to integer
13
0.582
Easy
587
https://leetcode.com/problems/roman-to-integer/discuss/2420141/Python-Simple-and-Easy-to-Understand-oror-O(N)-Time-Complexity
class Solution: def romanToInt(self, s: str) -> int: roman = {'I': 1, 'V': 5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} res = 0 for i in range(len(s)): if i+1 < len(s) and roman[s[i]] < roman[s[i+1]]: res -= roman[s[i]] else: ...
roman-to-integer
Python - Simple and Easy to Understand || O(N) Time Complexity
dayaniravi123
2
263
roman to integer
13
0.582
Easy
588
https://leetcode.com/problems/roman-to-integer/discuss/2071631/For-beginners-Python
class Solution: def romanToInt(self, s: str) -> int: # str -> list # group list by digits value_list = [] for symbol in s: if symbol == "M": value_list.append(1000) elif symbol == "D": value_list.append(500) elif sym...
roman-to-integer
For beginners, Python
a19941006
2
231
roman to integer
13
0.582
Easy
589
https://leetcode.com/problems/roman-to-integer/discuss/1881601/Easy-Python-Solution
class Solution: def romanToInt(self, s: str) -> int: ls = list(s) romD = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} stadD = {'IV':4, 'IX':9, 'XL':40, 'XC':90, 'CD':400, 'CM':900} val = 0 pos = 0 while(True): ...
roman-to-integer
Easy Python Solution
EvilGod_
2
712
roman to integer
13
0.582
Easy
590
https://leetcode.com/problems/roman-to-integer/discuss/1840914/Generalised-Python-3-Solution
class Solution: def romanToInt(self, s: str) -> int: convert = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 } out = 0 prev = 0 # store last added to compare to current ...
roman-to-integer
Generalised Python 3 Solution
rhinnawi95
2
256
roman to integer
13
0.582
Easy
591
https://leetcode.com/problems/roman-to-integer/discuss/1816357/Simple-Python-Solution-oror-92-Faster
class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ roman_symobols = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, } total = ...
roman-to-integer
Simple Python Solution || 92% Faster
depocoder
2
333
roman to integer
13
0.582
Easy
592
https://leetcode.com/problems/roman-to-integer/discuss/1743461/Python-3-or-Replacing-or-99.79-Faster-97.91-less-memory-usage-or
class Solution: def romanToInt(self, s: str) -> int: result = 0 values = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, # Substraction letters "Q": 4, "W": 9, "E": 40, "R": 90, "T": 400, "Y": 900, } # Replacing substractions replacements = { ...
roman-to-integer
Python 3 | Replacing | 99.79% Faster, 97.91% less memory usage |
anotherprogramer
2
271
roman to integer
13
0.582
Easy
593
https://leetcode.com/problems/roman-to-integer/discuss/1447129/Simple-40-ms-Pure-Python-Solution-7-lines
class Solution: def romanToInt(self, s: str) -> int: dic={"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000 } m,total=dic[s[0]],0 for i in s: n=dic[i] total = (total- 2*m + n) if(m<n) else (total+ n) m=n return total
roman-to-integer
Simple 40 ms Pure Python Solution , 7 lines
vineetkrgupta
2
339
roman to integer
13
0.582
Easy
594
https://leetcode.com/problems/longest-common-prefix/discuss/1351149/Python-and-startswith
class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: pre = strs[0] for i in strs: while not i.startswith(pre): pre = pre[:-1] return pre
longest-common-prefix
Python & startswith
lokeshsenthilkumar
72
4,500
longest common prefix
14
0.408
Easy
595
https://leetcode.com/problems/longest-common-prefix/discuss/484683/Python-3-(beats-~97)-(six-lines)
class Solution: def longestCommonPrefix(self, S: List[str]) -> str: if not S: return '' m, M, i = min(S), max(S), 0 for i in range(min(len(m),len(M))): if m[i] != M[i]: break else: i += 1 return m[:i] - Junaid Mansuri - Chicago, IL
longest-common-prefix
Python 3 (beats ~97%) (six lines)
junaidmansuri
65
12,000
longest common prefix
14
0.408
Easy
596
https://leetcode.com/problems/longest-common-prefix/discuss/1621297/python-runtimegreater94.46-and-memoryless81.95
class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: str1, str2 = min(strs), max(strs) i = 0 while i < len(str1): if str1[i] != str2[i]: str1 = str1[:i] i +=1 return str1
longest-common-prefix
python runtime>94.46% and memory<81.95%
fatmakahveci
29
2,700
longest common prefix
14
0.408
Easy
597
https://leetcode.com/problems/longest-common-prefix/discuss/1422342/Python-oror-Easy-Solution
class Solution: def longestCommonPrefix(self, lst: List[str]) -> str: ans = "" for i in zip(*lst): p = "".join(i) if len(set(p)) != 1: return (ans) else: ans += p[0] return (ans)
longest-common-prefix
Python || Easy Solution
naveenrathore
24
2,500
longest common prefix
14
0.408
Easy
598
https://leetcode.com/problems/longest-common-prefix/discuss/783976/Python-Simple-Solution-beats-100-runtime-12ms
class Solution(object): def longestCommonPrefix(self, strs): if len(strs) == 0: return "" s1, s2 = min(strs), max(strs) i = 0 while i < len(s1) and i < len(s2) and s1[i] == s2[i]: i += 1 return s1[:i]
longest-common-prefix
Python - Simple Solution, beats 100%, runtime 12ms
shaggy_x
13
1,600
longest common prefix
14
0.408
Easy
599