Vc6.0 right but leetcode wrong__Roman to Integer


  • 0
    R
    class Solution {
    public:
        int romanToInt(string s) {
            static int intnum=single2num(s[1]);
            int i,j;
            for(i=0,j=1;j<=s.length();i++,j++){
                if(single2num(s[j])>single2num(s[i]))
                intnum=intnum-single2num(s[i]);
                else{
                    if(j==1)
                    intnum=single2num(s[j])+single2num(s[i]);
                    else
                    intnum=intnum+single2num(s[j]);
                }
            }
            return intnum;
        }
        int single2num(int s){
            switch(s){
            case 'I': return 1;
            case 'V': return 5;
            case 'X': return 10;
            case 'L': return 50;
            case 'C': return 100;
            case 'D': return 500;
            case 'M': return 1000;
            }
        }
    };
    

    Roman to Integer my code is correct on my vc6.0
    but leetcode show below

    Submission Result: Wrong Answer
    Input: "DCXXI"
    Output: 554
    Expected: 621

    but on vc6.0, my code is correct and Output is 621
    Who knows what the matter is?


Log in to reply
 

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