C++ istringstream try


  • 0
    J
    class Solution {
    public:
        int countSegments(string s) {
            istringstream input(s);
            int count = 0;
            string tmp;
            while (getline(input, tmp, ' ')) if (!tmp.empty()) count++;
            return count;
        }
    };
    

Log in to reply
 

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