Zig Zag Conversion Algorithm

art Deco, sometimes referred to as Deco, is a style of visual arts, architecture and design that first looked in France exactly before universe War I. art Deco influenced the design of buildings, furniture, jewelry, style, cars, movie theatres, trains, ocean liners, and everyday objects such as radios and vacuum cleaners. From its outset, art Deco was influenced by the bold geometric forms of Cubism and the Vienna Secession; the bright colors of Fauvism and of the ballet Russes; the updated craftsmanship of the furniture of the eras of Louis Philippe I and Louis XVI; and the exotic styles of China and Japan, India, Persia, ancient Egypt and Maya art.
class Solution {
public:
    string convert(string s, int nRows) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function    
        
        if (nRows == 1) return s;
        string result;
        if (s.size() == 0) return result;

        int delta = nRows*2-2;
        for (int i = 0; i < nRows; i++) {
            for (int j = i; j < s.size(); j += delta) {
                result += s[j];
                if (i == 0 || i == nRows-1) continue;
                if (j + (nRows-i-1)*2 < s.size())
                    result += s[j+(nRows-i-1)*2];
            }
        }
        return result;
    }
};

LANGUAGE:

DARK MODE: