java cursive solution


  • 0
    L

    '''class Solution {
    public String countAndSay(int n) {
    if(n ==1 ){
    return "1";
    }else{
    return so( countAndSay(n-1));
    }
    }
    public String so(String str){
    str= str+"!";
    String result = "";
    int i=0;
    int count=1;
    while( i+1 <str.length()){

    		if(str.charAt(i)==str.charAt(i+1)){
    			count++;
    			i++;
    
    		}
    		else
    		{
    			result = result + count+str.charAt(i);
    			count =1;
    			i++;
    
    		}
    
    	}
    	return result;
    }
    

    }
    '''


Log in to reply
 

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