Java Solution gives compilation error(reached end of file while parsing) on Leetcode, but none on my machine


  • 2
    D
    import java.util.*;
      
    public class Solution{
    
        public static int romanToInt(String s) {
    
            int len =s.length();
    
            HashMap<Character, Integer> val = new HashMap<Character, Integer>();
    
    
            val.put('I', (int)1);
    
            val.put('V', (int)5);
    
            val.put('X', (int)10);
    
            val.put('L', (int)50);
    
            val.put('C', (int)100);
    
            val.put('D', (int)500);
    
            val.put('M', (int)1000);
    
            int num=0;
    
            for (int i=0;i<len;i++)
    
            {
    
                char c=s.charAt(i);
    
                int digit = val.get(c);
    
    
                if (i == 0)
    
                {
    
                    num+= digit;
    
                }
    
                else {
    
                    int prev = val.get(s.charAt(i-1));
    
                    if ( digit <= prev)
    
                        num+= digit;
    
                    else if (digit> prev)
    
                        num+= digit - 2*prev;
    
                }//if
    
    
    
             }//for
    
            return num;
    
    
        }//
    
    }

  • 0
    A

    Even I am facing the same issue.
    Is there an answer here ?


Log in to reply
 

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