[Leetcode - Medium] Restore Ip Addresses #39
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
문제
Constraints
Edge Case
12보다 s의 길이가 크면 절대 ip로 만들어질 수 없기에 빈 배열 반환
풀이
dfs를 돌 때, 마지막으로 점을 찍은 자릿수(pos)를 저장한다.
만약, IP를 구성하기 위해 쪼갠 문자열 배열(arr)이 4개 보다 많다면 IP가 성립할 수 없기에 그냥 return한다.
만약, pos가 s의 길이만큼 되었고, arr의 길이가 4라면 제대로된 IP이기에 res에 push한다.
2~3의 케이스가 아니라면, pos를 기준으로 시작점을 잡고, 이 시작점에서 한자리 ~ 세자리 사이의 숫자를 만들어서 arr에 넣고 다음 재귀로 넘어간다.
=> 다만, 해당 숫자가 0 ~ 255 사이여야 하며, 또한 0이 앞에 있으면 넘어가지 않는다.
어려웠던 점
X
알게된 점
X