I dont know the problem that input '1' my output is '11' is not right? the system says should be '1'


  • 1
    S
    public class Solution {
        public String countAndSay(int n) {
            StringBuilder str = new StringBuilder();
            int count = 1;
            int num;
            while(n > 0) {
                num = n % 10;
                if(num == ((n-num)/10)%10) {
                    count++;
                } else {
                    str.insert(0, count+""+num);
                }
                n = (n-num) / 10;
            }
            return str.toString();
        }
    }

  • 0
    B

    I am faced with the same problem as you. Did you got the answer?


  • 0
    S

    yes, I got it long ago, the argument int n in the function means the index not the input number array


  • 0
    B

    Thans for your reply. And I understand the meaning of the problem now.


  • 0
    L

    So, where is the input array then?


  • 0
    S

    no input array, just find out the law and push forward the array from base


Log in to reply
 

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