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

17-InSange #64

Merged
merged 2 commits into from
Jul 10, 2024
Merged

17-InSange #64

merged 2 commits into from
Jul 10, 2024

Conversation

InSange
Copy link
Collaborator

@InSange InSange commented Jun 28, 2024

πŸ”— 문제 링크

Zigzag Conversion

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1μ‹œκ°„

✨ μˆ˜λ„ μ½”λ“œ

풀이 방식

image

λ¬Έμžμ—΄μ„ λ°©λ¬Έν•˜λŠ”λ° 각자 행에 ν•΄λ‹Ήν•˜λŠ” 배열에닀가 ν•˜λ‚˜μ”© μ§‘μ–΄λ„£λŠ” μ‹μœΌλ‘œ μ±„μ›Œμ€€λ‹€.
0번째 ν–‰κ³Ό N-1번째 행일 λ•Œλ§ˆλ‹€ μΆ”κ°€ν•΄μ£ΌλŠ” λ°©ν–₯을 μ „ν™˜μ‹œμΌœμ€€λ‹€.

class Solution {
public:
    string convert(string s, int numRows) {
        if(numRows <= 1 || s.size() <= numRows) return s;
        
        vector<string>v(numRows, "");
        
        int i, j, dir;
        j = 0;
        dir = -1;
        
        for(i = 0; i < s.size(); i++)
        {
            if(j == numRows - 1 || j == 0) dir *= -1;
            v[j] += s[i];
            if(dir == 1) j++;
            else j--;
        }
        
        string answer;
        answer = "";
        
        for(auto c : v)
        {
            answer += c;
        }
        
        return answer;
    }
};

image

ν›„κΈ°

μ²˜μŒμ— μ ‘κ·Όν•  λ•Œ κ·œμΉ™μ΄ μžˆμ„ 것이라고 νŒλ‹¨ν•˜μ˜€λŠ”λ° 였히렀 더 λ‹¨μˆœνžˆ μ™”λ‹€κ°”λ‹€ν•˜λ©΄ λ˜λŠ” 뢀뢄이라 쑰금 ν—·κ°ˆλ¦° μ μ™Έμ—λŠ” μ—†μ—ˆλ‹€. λ°©ν–₯만 잘 작으면 λ¬΄λ‚œν•œ 정도?

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 μ²˜μŒμ— 문제 읽고 νŒ¨ν„΄ νŒŒμ•…ν•˜λ©΄ 될 것 κ°™μ•˜λŠ”λ° 되렀 직접 μ™”λ‹€κ°”λ‹€ ν•˜λŠ”κ²Œ 더 λ‚˜μ€ μΌ€μ΄μŠ€λ„ μžˆλ„€μš” γ…‹γ…‹ λ°©ν–₯을 -1μ”© κ³±ν•΄μ„œ μƒν•œκ³Ό ν•˜ν•œμ„ μ™”λ‹€κ°”λ‹€ ν•˜λŠ” 뢀뢄이 μΈμƒμ μ΄λ„€μš”.

Copy link
Collaborator

@seongwon030 seongwon030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1을 계속 κ³±ν•΄μ£Όλ©΄μ„œ μ§€κ·Έμž¬κ·Έμ²˜λŸΌ μ›€μ§μ—¬μ„œ 각 ν–‰μ˜ λ¬Έμžμ—΄μ„ 계속 λ”ν•΄μ£ΌλŠ” λ¬Έμ œμ˜€κ΅°μš”. κΉ”λ”ν•œ μ½”λ“œ 잘 λ΄€μŠ΅λ‹ˆλ‹€!

@InSange InSange merged commit 9e7dc6e into main Jul 10, 2024
@InSange InSange deleted the 17-InSange branch July 10, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants