Clean Java solution


  • 0
    M
    public int countSegments(String s) {
     int ret = 0;
     boolean bool = false;
     for(int i=0; i<s.length(); i++){
        if(s.charAt(i)!=' ' && bool==false){
            ret++;
            bool=true;
        }else if(s.charAt(i)==' '){
            bool=false;
        }
     }
     return ret;
    }
    

    }


Log in to reply
 

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