👨‍💻
Hamin TIL
  • Today I Learned 🧑🏻‍💻
  • 회고
  • git
    • git_basics
      • Git 101
      • Git branch
      • Git_ignore
    • Git Book
    • 우아한형제들
    • pull_request
  • db
    • DA
      • 데이터표준화
      • 데이터_요건분석
      • 전사아키텍처_이해
      • 데이터모델링
    • SQL
      • SQL기본및활용
        • SQL활용
          • 절차형SQL
          • 계층형질의와셀프조인
          • DCL
          • 그룹함수
          • 윈도우함수
          • 표준조인
          • 집합연산자
          • 서브쿼리
        • SQL고급활용및튜닝
          • 옵티마이저와실행계획
          • 조인수행원리
          • 인덱스기본
        • SQL기본
          • 함수
          • 관계형데이터베이스개요
          • GROUPBY,HAVING절
          • DDL
          • 조인
          • ORDERBY절
          • DML
          • WHERE절
          • TCL
      • 데이터모델링의이해
        • 데이터모델과성능
          • 정규화의 성능
          • 데이터베이스구조와성능
          • 분산데이터베이스와성능
          • 대량 데이터에 따른 성능
          • 반정규화와 성능
          • 성능데이터모델링의 개요
        • 데이터모델링의이해
          • 식별자
          • 속성
          • 관계
          • 엔터티
          • 데이터 모델의 이해
    • DB
  • trouble
    • libomp
    • After macOS update, git command
    • system
  • algorithm
    • BOJ
      • 평범한 배낭
      • 17825-주사위윷놀이
      • 14888-연산자끼워넣기
      • 14503-로봇청소기
      • 10157
      • 14502-연구소
      • 18428-감시피하기
      • 14501
      • 18405-경쟁적전염
      • 14499-주사위굴리기
      • 16236-아기상어
      • 15686-치킨배달
      • 19237-어른상어
      • 16234-인구이동
      • 19236-청소년상어
      • 1339-단어수학
      • 리모콘
      • 18353 - 병사배치하기
      • 18352-특정거리의도시찾기
      • 12100-2048
      • N-Queen
      • 3190-뱀
      • 11724
    • programmers
      • 영어끝말잇기
      • 기둥과 보
      • H - index
      • 정수삼각형
      • 2018 KAKAO BLIND RECRUITMENT - 압축
      • 삼각달팽이
      • 거스름돈
      • [1차] 셔틀버스
    • data_structure
      • Queue
      • Graph
      • Stack
      • Hash table
    • implementation
      • dynamic_programming
      • sort
      • Least common multiple
      • dfs
      • dijkstra
      • bfs
      • binary_search
    • aps
      • notes
    • modules
  • python
    • requirements.txt
    • Jupyter notebook
    • 00_들어가기 전에
    • Python Virtual Environment
    • Python Syntax
  • django
    • Class Based View in Django
    • Model in Django
    • URL Name
    • Form and ModelForm
    • Authentication
    • Tips & Tricks
    • Optimization
    • Request and Response Objects
    • Templates
    • Variable Routing & DTL
    • Django REST API with JSON web token (JWT)
    • Intro to Django
    • Django REST Framework
    • Wrap-up
    • Image Upload
  • javascript
    • Ajax (Asynchronous Javascript And XML)
    • Document Object Model
    • Java Script 101
    • ES (ECMAscript)
  • java
    • Java 101
  • aws
    • beginning_cloud_computing_with_aws
      • 02 AWS 주요 서비스 이해하기
      • 01 아마존 웹 서비스 Cloud 개요
  • programming
    • Communication
    • CS_용어사전
  • vue.js
    • 01_Vue.js_Intro
  • data_science
    • 01_데이터에서인사이트발견하기
    • pandas
    • 04_데이터분류모델
    • 02_텍스트마이닝첫걸음
    • 05_종합예제
    • 03_미래를예측하는데이터분석
    • Statistics
      • 모수와 추정량
    • 통계학노트
  • linux
    • Linux Commands
  • ide
    • VScode
    • Pycharm
  • html,css
    • HTML 101
    • CSS 101
  • colab
    • colab_101
  • 의사결정나무및모형비교
Powered by GitBook
On this page

Was this helpful?

  1. algorithm
  2. programmers

2018 KAKAO BLIND RECRUITMENT - 압축

Previous정수삼각형Next삼각달팽이

Last updated 4 years ago

Was this helpful?

  • aps

    w 와 c 를 msg 를 슬라이싱해서 구현.

    1. 상황마다 msg 를 슬라이싱하는 시작점 s 와 얼마만큼 슬라이싱할 간격 L 을 사용

    ``` dic = {'A' : 1 ,,,} a([]): 결과로 출력할 list, wc 를 그 때마다 append가

    s(0): msg 에서 w 로 입력받을 슬라이싱 인덱스 시작점. l(1): msg 에서 s부터 얼마만큼 더가서 슬라이싱할 것인지. w = msg[s : s + l] c = msg[s + l : s + l + 1]

    s = 0 l = 1

    while True:

    w = msg[s : s + l]
    c = msg[s + l : s + l + 1]
    
    wc 가 사전에 있으면
        l += 1
        # 존재하는 wc 가 끝까지라면, wc 사전번호 a에 추가하고, a 반환하고 종료
    
    wc 가 사전에 없으면
        w 사전번호 a 에 추가 (출력용)
        wc 사전에 추가
        s += l
        l = 1
    
        # s == len(msg) - 1 이면
            msg[s:s+l] 의 사전번호 a 에 추가하고, a 반환하고 종료.
```python
def solution(msg):
    dic = dict()
    lst = [chr(i) for i in range(ord('A'), ord('Z') + 1)]

    for idx, char in enumerate(lst):
        dic[char] = idx + 1

    a = []
    s = 0
    l = 1

    while True:
        w = msg[s : s + l]
        c = msg[s + l:s + l + 1]

        if (w + c) in dic:
            l += 1
            if (s + l) >= len(msg):
                a.append(dic[w + c])
                return a

        else:
            a.append(dic[w])
            dic[w + c] = len(dic) + 1
            s += l
            l = 1

            if s == len(msg) - 1:
                a.append(dic[msg[s: s + l]])
                return a
https://programmers.co.kr/learn/courses/30/lessons/17684