Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zigzag Conversion #28

Closed
Tracked by #100
fkdl0048 opened this issue Jul 13, 2024 · 0 comments
Closed
Tracked by #100

Zigzag Conversion #28

fkdl0048 opened this issue Jul 13, 2024 · 0 comments
Assignees

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Jul 13, 2024

class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows <= 1) {
            return s;
        }

        vector<string> v(numRows, "");

        int j = 0, dir = -1;

        for (int i = 0; i < s.length(); i++)
        {
            if (j == numRows - 1 || j == 0)
            {
                dir *= -1;
            }
            
            v[j] += s[i];
            if (dir == 1) j++;
            else j--;
        }

        string res;
        for (auto &it : v)
        {
            res += it;
        }

        return res;
    }
};

// if numsRows = 3
// 0,    4,    8,     12
// 1, 3, 5, 7, 9, 11, 13
// 2,    6,    10

// if numsRows = 4
// 0,      6,       12,
// 1,   5, 7,    11,13,
// 2, 4,   8, 10,   14,
// 3,      9,       15,

// 배열을 N개만큼 만들고 현재 인수에서 N개까지 증가, N개만큼 감소 반복.
// 배열 순서대로 붙이기
@fkdl0048 fkdl0048 mentioned this issue Jul 13, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Jul 13, 2024
@fkdl0048 fkdl0048 added this to Todo Jul 13, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Jul 13, 2024
@fkdl0048 fkdl0048 changed the title Longest Palindromic Substring 6. Zigzag Conversion Jul 13, 2024
@fkdl0048 fkdl0048 changed the title 6. Zigzag Conversion Zigzag Conversion Jul 13, 2024
@fkdl0048 fkdl0048 moved this from Todo to In Progress in Todo Jul 13, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Todo Jul 23, 2024
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
47 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant