TIL (today I learned)
2019-03-13 TIL
grin-quokka
2019. 3. 13. 18:19
프로그래머스 ) 자료구조와 알고리즘
-
선형 배열
정렬된 리스트에 원소 삽입
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 |