Memory Limit Exceeded.. Why??


  • 0
    P
    public class Solution {
    public String convert(String s, int nRows) {
        int len = s.length();
        if(len <= nRows)
            return s;
        StringBuffer result = new StringBuffer();
        for(int i = 0; i < nRows; i++) {
            int k = i;
            while(k < len) {
                result.append("" + s.charAt(k));
                if(i == 0 || i == nRows - 1) {
                    k += nRows;
                    k += nRows - 2;
                }
                else {
                    k += nRows - 1;
                }
            }
        }
        return result.toString();
    }
    

    }


  • 0
    E

    Consider the corner situation with nRows =1, you would never get out of the while loop.


Log in to reply
 

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