Please help me to get out of Memory limit exceed error


  • 0
    T

    ...
    public class Solution {
    public String convert(String s, int numRows) {
    StringBuilder str = new StringBuilder("");
    int startindex=0;
    int skip=0;
    for(int i=1;i<=numRows;i++){
    if(i%2==0)
    skip=numRows-2;
    else
    skip=3*(numRows/2)-1;
    startindex=i-1;
    if(startindex<s.length())
    str.append(s.charAt(startindex));
    while(startindex+skip+1<s.length()){
    str.append(s.charAt(startindex+skip+1));
    startindex+=skip+1;
    }
    }
    return str.toString();
    }
    }
    ...


Log in to reply
 

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