Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 추천시스템
- Python
- pytorch
- 협업 필터링
- TF-IDF
- 딥러닝
- codingtest
- 시각화
- 데이터 엔지니어링
- 추천 시스템
- Overfitting
- 코테
- 알고리즘
- 머신러닝
- 웹스크래핑
- 분산 시스템
- coursera
- 백준
- wordcloud
- 웹크롤링
- 부스트캠프
- 데이터
- Tensor
- 프로그래머스
- Cosine-similarity
- selenium
- 파이썬
- SGD
- 코딩테스트
- recommendation system
Archives
- Today
- Total
개발자식
[Codility_Lesson 4] FrogRiverOne 본문
문제 : FrogRiverOne
Test results - Codility
A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river. You are given an array
app.codility.com
문제 해석 :
개구리가 강을 건너기 위해 나뭇잎이 1부터 X까지 (위치)떨어져 있어야 한다.
배열A는 시간(인덱스)에 따라 떨어지는 위치가 담겨있다.
나의 코드
- all, any를 이용하여 떨어진 여부를 확인했더니 효율성 tc 2개를 만족시키지 못했다.
정답 코드
def solution(X, A):
temp =[0] * (X+1)
check_sum =0
for i in range(len(A)):
if temp[A[i]]==0:
temp[A[i]]+=1
check_sum+=1
if check_sum==X:
return i
return -1
- 해당 위치가 나뭇잎이 떨어지지 않은 경우 (즉 해당 temp 값이 0인 경우) 만 chek_sum의 +1 하고 바로 return 할 수 있게 한다.
'Algorithm > Codility' 카테고리의 다른 글
[Codility Lesson4] PermCheck (0) | 2022.06.30 |
---|---|
[Codility Lesson4] Counting Elements_MissingInteger (0) | 2022.06.30 |
[Codility Lesson17] Dynamic programming_NumberSolitaire (0) | 2022.06.29 |
[Codility Lesson3] Time Complexity_ TapeEquilibrium (0) | 2022.06.29 |
[Codility Lesson3] PermMissingElem (0) | 2022.06.29 |
Comments