TWO lines in total, beat 80% c++!!!!!!

  • 0

    If we don't count in variable declaration & return clauses, it just takes two lines!

      string encode(vector<string>& strs) {
          string s;
          for (auto it =strs.begin(); it!=strs.end(); it++) s+=(*it)+'\n';
          return s;    
    vector<string> decode(string s) {
        vector<string> strs;
        stringstream ss(s);
        string s1;
        while ( getline(ss,s1)) strs.push_back(s1);
        return strs;   

Log in to reply

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