For Zigzag problem


  • 0
    F

    class Solution {
    public:
    string convert(string s, int nRows) {
    if (nRows==1||s.length()==0){
    return s;
    }
    int len=s.length();
    string ans="";
    for(int i=0;i<nRows&& i< len;i++){
    if(i==0||i==nRows-1){
    int pos=i;
    while(pos<len){
    ans+=s[pos];
    pos+=pos+2nRows-2;
    }
    }
    else{
    int pos=i;
    while(pos<len){
    ans+=s[pos];
    int pos2=pos+2
    nRows-2-2i;
    if(pos2<len){
    ans+=s[pos2];
    }
    pos+=pos+2
    nRows-2;
    }
    }
    }
    return ans;
    };

    I cannot find what's wrong with my code!


  • 0
    A

    Please format your code using code tag, otherwise it's impossible to check your code.


Log in to reply
 

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