1. 程式人生 > >722. Remove Comments

722. Remove Comments

+= n) move col push_back nts length tin side

class Solution {
public:
    vector<string> removeComments(vector<string>& source) {
        vector<string> res;
        string ln;
        int state = 0;
        for (const auto & line : source) {
            for (int i = 0, ll = line.length(); i < ll; i++) {
                
if (state == 0) { if (i < ll-1) { if (line[i] == / && line[i+1] == /) break; // // comment, skip line else if (line[i] == / && line[i+1] == *) { state = 1; i
+= 1; continue; } } ln.push_back(line[i]); } else if (state == 1) { // inside /* if (i < ll-1 && line[i] == * && line[i+1] == /) { state
= 0; i += 1; continue; } } } if (state == 0 && ln.length() > 0) { res.push_back(ln); ln = ""; } } if (ln.length() > 0) res.push_back(ln); return res; } };

722. Remove Comments