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 |
Tags
- 오라클
- 트레이딩 봇 만들기
- WAS WebServer 차이
- beautifulsoup
- spring
- 리눅스
- 프로그래머스 SQL
- 리눅스 777
- string format
- JSON특징
- JavaScript Obejct Notation
- 변동성 돌파전략
- 프로그래머스
- pybithumb
- 와스 웹서버의 차이
- 프로그래머스 소수
- 리눅스 rwx
- Web Service Architecture
- WAS란
- 단순 반복 자동화
- 파이썬 가상환경
- Web Server란
- java
- JSON 형식
- Python
- 파이썬
- 즐겨찾기가 가장 많은 식당 정보 출력하기
- 빗썸 API 사용
- BigDecimal
- 파이썬 주식
Archives
- Today
- Total
IT 개발자_S
해커랭크 Climbing the leaderboard 본문
반응형
1. 입력값 배열이 주어지고, 해당하는 점수를 삽입 했을때 해당 점수의 rank를 output 함
여기서 배열에 추가하고 중복값을 제거하여 .rank 를 부여했지만
이중 for문 O(n^2) 으로 인해 runtime error 발생
0#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the climbingLeaderboard function below.
def climbingLeaderboard(scores, alice):
res =[] # 정답
rankArr= [] # rank
rank = 0 #순위
cnt = 0
for i in range( len(alice)) :
scores.append(alice[i])
rankArr = list(set(scores))
rankArr.sort(reverse=True)
# 100 50 40 20 5
print(rankArr)
rank =0
for j in range (len(rankArr)) :
rank +=1
if(rankArr[j] == alice[i]) :
res.append(rank)
return res
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
scores_count = int(input())
scores = list(map(int, input().rstrip().split()))
alice_count = int(input())
alice = list(map(int, input().rstrip().split()))
result = climbingLeaderboard(scores, alice)
fptr.write('\n'.join(map(str, result)))
fptr.write('\n')
fptr.close()
해결방안.
idx 를 통하여 runtime error 방지 및 for문을 한번 사용하여 해결
0#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the climbingLeaderboard function below.
def climbingLeaderboard(scores, alice):
res =[] # 정답
# alice 오름차순 #scores 내림차순
# idx 를 이용
idx = 0
# 6 4 2 1
# 100 50 40 20 10
leaderboard = sorted(set(scores), reverse = True)
idx = len(leaderboard)
for a in alice :
print("a",a)
while (leaderboard[idx -1] <= a and idx >0) :
idx -=1
if(idx <0) :
res.append(1)
continue
res.append(idx+1)
return res
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
scores_count = int(input())
scores = list(map(int, input().rstrip().split()))
alice_count = int(input())
alice = list(map(int, input().rstrip().split()))
result = climbingLeaderboard(scores, alice)
fptr.write('\n'.join(map(str, result)))
fptr.write('\n')
fptr.close()
반응형
Comments