Too easy!!!


  • 0

    Non-space characters' ascii codes are larger than 32, which means white space characters' ascii codes are smaller than 33.

    int countSegments(char* s) {
        int len = strlen(s);
        int ct = 0;
        bool whitespace = true;
        int i = 0;
        while(i < len) {
            if(s[i++] < 33) {
                whitespace = true;
                continue;
            }
            if(whitespace) {
                ++ct;
                whitespace = false;
            }
        }
        return ct;
    }
    

Log in to reply
 

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