Incorrect test case


  • 0
    U

    My code failed on test case "10". My code's output is 2 and expected output is 1. Isn't that incorrect? Clearly "A" and "J" are answers to that question. Here's my code:

        
        public int oneDigit(int s) {
            return s==0 ? 0 : 1;
        }
        
        public int twoDigits(int s) {
            return (s>0 && s<27) ? 1 : 0;
        }
        
        public int numDecodings(String s) {
            if(s==null || s.isEmpty())  return 0;
          
            int len = s.length();
            
            if(len==1)  return oneDigit(Integer.parseInt(s));
            
            int a = Integer.parseInt(s.substring(0,1));
            int b = Integer.parseInt(s.substring(0,2));
            
            return oneDigit(a) + twoDigits(b) + numDecodings(s.substring(1, len)) + numDecodings(s.substring(2, len));
        }
    

Log in to reply
 

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