My Output is the same as expected, why give me a WA.


  • 0
    J

    class Solution {
    public:
    string convert(string s, int numRows) {
    int len = s.length();
    if(len <= 1 || numRows <=1) return s;
    string as;
    for(int i = 1; i <= numRows; ++i) {
    int start = i - 1;
    int now = start;
    as += s[now];
    int step1 = (numRows -1) * 2 - (i - 1) * 2;
    int step2 = (numRows -1) * 2 - step1;
    if(step1 == 0 && step2 == 0) continue;
    while(true) {
    if(now + step1 < len) {
    now += step1;
    if(step1 != 0) {
    as += s[now];
    }
    } else {
    break;
    }
    if(now + step2 < len) {
    now += step2;
    if(step2 != 0) {
    as += s[now];
    }
    } else {
    break;
    }
    }
    }
    return as;
    }
    };

    why the response is "

    Input: "AB", 3

    Output: "AB"

    Expected: "AB"

    "


Log in to reply
 

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