Rome to integer in C#


  • 0
    L

    public class Solution {
    public int RomanToInt(string s)
    {
    int a = 0;
    int count = 0;
    for (int i=0; i< s.Length ;i++)
    {
    string ss = s.Substring (i,1);
    switch(ss)
    {
    case "I":
    a += 1;
    break;

            case "V":
                a += 5 ;
                break;
                    
            case "X": 
                a += 10    ;                
                break;
                    
            case "L":
                a += 50;
                break;
                    
            case "C":
                a += 100;
                break;
            case "D":
                a += 500;
                break;
            case "M":
                a += 1000;
                break;
             }
        
        count +=1;
       }
        return a;
    }
    

    }

    //use the simplest way


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.