leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1324.cpp (605B)


      1 class Solution {
      2   public:
      3     vector<string> printVertically(const string &s) {
      4         vector<string> vec, res;
      5 
      6         string tmp, buf;
      7         stringstream ss(s);
      8         while (ss >> tmp)
      9             vec.push_back(tmp);
     10 
     11         for (int i = 0; true; i++) {
     12             tmp.clear(), buf.clear();
     13             for (const string &s : vec) {
     14                 if (s.size() <= i)
     15                     buf += " ";
     16                 else
     17                     tmp += buf + s[i], buf.clear();
     18             }
     19             if (!tmp.size()) break;
     20             res.push_back(tmp);
     21         }
     22         return res;
     23     }
     24 };