File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed 
problems/leet-code/top-150-interview/string Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ class  Solution :
2+     """ 
3+         Runtime: 42ms | Beats: 80.13% 
4+ 
5+         Got help from Jadi :) 
6+     """ 
7+     
8+     def  romanToInt (self , s : str ) ->  int :
9+         conversion  =  {
10+             "I" : 1 ,
11+             "V" : 5 ,
12+             "X" : 10 ,
13+             "L" : 50 ,
14+             "C" : 100 ,
15+             "D" : 500 ,
16+             "M" : 1000 ,
17+             "IV" : 4 ,
18+             "IX" : 9 ,
19+             "XL" : 40 ,
20+             "XC" : 90 ,
21+             "CD" : 400 ,
22+             "CM" : 900 
23+         }
24+ 
25+         result  =  0 
26+         counter  =  0 
27+         while  (counter  <  len (s )):
28+             if  s [counter :counter + 2 ] in  conversion :
29+                 result  +=  conversion [s [counter :counter + 2 ]]
30+                 counter  +=  2 
31+             else :
32+                 result  +=  conversion [s [counter ]]
33+                 counter  +=  1 
34+ 
35+         return  result 
36+ 
37+ 
38+ problem_link  =  "https://leetcode.com/problems/roman-to-integer/submissions/1389192837/?envType=study-plan-v2&envId=top-interview-150" 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments