Roman Number to Integer ans class Solution: def romanToDecimal(self, S): roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} result = 0 prev_value = 0 for i in range(len(S) - 1, -1, -1): current_value = roman_values[S[i]] if current_value < prev_value: result -= current_value else: result += current_value prev_value = current_value return result
subscribed to your channel, please upload daily, even if i solve it on my own i'll look after your code ( to understand efficiency)
Sure.
How did you know all the ans i spend 3 and half hour but still it won't pass all the test cases.
Plz make a video how to approch to the problems
It's just practice that I have done a lot 😃
please do live for weekly contest and jobathon
Will try uploading it or doing it live.
Roman Number to Integer
ans
class Solution:
def romanToDecimal(self, S):
roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
result = 0
prev_value = 0
for i in range(len(S) - 1, -1, -1):
current_value = roman_values[S[i]]
if current_value < prev_value:
result -= current_value
else:
result += current_value
prev_value = current_value
return result
Thanks bro
superb explained
i also tried this problem by myself but i wasn't getting the right answer as i was doint (n%26 - 1) + 'A' thanks for the explanation