Simple Java Solution (Beats 100%)


  • 1
    int segs = 0;
    char[] chars = s.toCharArray();
    for(int i=0;i<chars.length;i++) {
        if(chars[i]!=' ') segs++;
        while(i<chars.length && chars[i]!=' ') i++;
    }
    return segs;
    

    0_1481379440769_Screen Shot 2016-12-10 at 15.15.25.png


Log in to reply
 

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