Wrong expected answer in JAVA


  • -1
    A

    Precise correct solution but not accepted by LeetCode. Anyone knows why?

    public class Solution {
        public String countAndSay(int n) {
           String output = "";
           char [] temp = String.valueOf(n).toCharArray();
           int i=0;
           int count=1;
           while(i<(temp.length -1)){
                if(temp[i]==temp[i+1])
                    count++;
                else{
                   output = output + count + ""+ temp[i];
                   count =1;
                }
                i++;
           }
           output = output + count + ""+ temp[i];
           return output;
        }
    }

Log in to reply
 

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