상위 150개 인터뷰쉬움

문자열 인코딩 및 디코딩

'문자열 인코딩 및 디코딩' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

문자열 목록을 단일 문자열로 인코딩하는 알고리즘을 설계합니다. 그런 다음 인코딩된 문자열은 원래 문자열 목록으로 다시 디코딩됩니다.

두 가지 기능을 구현합니다.

- encode(strs: List[str]) -> str — 문자열 목록을 단일 문자열로 인코딩합니다.

- decode(s: str) -> List[str] — 단일 문자열을 원래 문자열 목록으로 다시 디코딩합니다.

인코딩된 문자열은 특수 문자 및 빈 문자열을 포함하여 입력 문자열에서 가능한 모든 문자를 처리할 수 있어야 합니다.

제약
  • 0 <= len(strs) <= 200
  • 0 <= len(strs[i]) <= 200
  • strs[i] can contain any possible characters (0-255)

Example 1
Input
strs = ["hello", "world"]
Output
["hello", "world"]
Explanation

The list is encoded into a single string and then decoded back to the original list ["hello", "world"].

Example 2
Input
strs = [""]
Output
[""]
Explanation

A list containing a single empty string is encoded and decoded correctly.

Example 3
Input
strs = ["we", "say", ":", "yes"]
Output
["we", "say", ":", "yes"]
Explanation

Special characters like ":" are handled correctly during encoding and decoding.

Need a Hint?
세트나 힙과 같은 배열 및 해싱 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.