프로그래머스 ) 자료구조와 알고리즘
-
선형 배열
정렬된 리스트에 원소 삽입
1 2 3 4 5 6 7 8 | def solution(L, x): if x > L[-1]: L.append(x) return L for index in range(len(L)): if x < L[index]: L.insert(index, x) return L | cs |
- 리스트에서 원소 찾아내서 인덱스 번호로 이루어진 리스트 리턴 (중복 포함)
1 2 3 4 5 6 7 8 9 | def solution(L, x): if x not in L: answer = [-1] else: answer = [] for i in range(len(L)): if x == L[i]: answer.append(i) return answer | cs |
'TIL (today I learned)' 카테고리의 다른 글
코드스테이츠 5주차 후기 (0) | 2019.06.09 |
---|---|
2019-03-15 TIL (0) | 2019.03.15 |
2019-03-11 TIL (0) | 2019.03.11 |
2019-03-10 TIL (0) | 2019.03.11 |
2019-02-26 TIL (0) | 2019.02.26 |