It' s a foolish method!


  • 0
    L
    string convert(string s, int numRows) {
        if (numRows == 1) return s;
    
        string str;
        int dis = numRows * 2 - 2;
        int pos_max = dis;
    	bool last = false;
    	for (int i = 0; i < numRows; i++) {
    		for (int j = i, dis_t = dis; j < s.size(); j += dis_t) {
                str += s[j];
    			if (j!= i && i > 0 && i < numRows - 1)
    				dis_t = pos_max - dis_t;
    		}
    		if (last) break;
    		else if ((dis -= 2) ==  0) {
    			last = true;
    			dis = pos_max;
    		}
        }
        return str;
    }

Log in to reply
 

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