반응형
https://leetcode.com/problems/zigzag-conversion/
Zigzag Conversion - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
fun convert(s: String, numRows: Int): String {
var direction = 0
var zigzagIdx = 0
val zigzagTable = mutableMapOf<Int, String>()
s.forEach {
if (zigzagIdx == 0) {
direction = 1 // down(index plus)
} else if(zigzagIdx == numRows - 1) {
direction = -1 // up(index minus)
}
zigzagTable.set(
key = zigzagIdx,
value = zigzagTable.getOrDefault(zigzagIdx, "") +it
)
zigzagIdx += direction
}
return zigzagTable.values.joinToString("")
}
}
https://github.com/960813/leetcode-problems/commit/073a633dc09ee2539adf2d973e2b191bb0820c5d
[6] Kotlin · 960813/leetcode-problems@073a633
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
github.com
반응형
☕️ Networking
기술 직군의 기술적인 교류, 커리어 이야기, 직군 무관 네트워킹 모두 환영합니다!
위클리 아카데미 오픈 채팅방(비밀번호: 9323)
kakaotalk: https://open.kakao.com/o/gyvuT5Yd