Loading...

lesson 2. cyclicrotation

결과 위치는 (현재 인덱스 + 이동한 횟수) % 배열 길이로 구하고 배열에 (이동된 결과 위치, 현재 값)을 집어넣은 후 정렬하여 인덱스 순서대로 값이 나오도록 구현했다 # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A, K): temp=[] for i,a in enumerate(A): temp.append(((i+K)%len(A),a)) temp.sort() ans=[] for i,j in temp: ans.append(j) return ans 이렇게 슬라이싱으로 푸는 방법도 있다 def solution(A, K): # write your code in Python ..

[프로그래머스] 땅따먹기 (파이썬, javascript )

dp 문제 열이 연속으로 같지 않게 최대값 구하는 문제 1. 파이썬 def solution(land): for i in range(1,len(land)): for j in range(4): land[i][j]+=max(land[i-1][:j]+land[i-1][j+1:]) return max(land[len(land)-1]) 2. javascript function solution(land) { var answer = 0; let n=land.length; let dp=Array(n).fill(0).map(()=>Array(4).fill(0)); for(let j=0;j

[프로그래머스] h-index (파이썬, javascript)

1. javascript 가장 큰 인용 가능 수 =논문 개수, 최소=0 나는 완전탐색으로 했다 function solution(citations) { var answer = 0; for(let i=citations.length;i>=0;i-=1){ const arr=citations.filter(x=>x>=i); if(arr.length>=i && citations.length-i0: cnt=0 for c in citations: if c>=idx: cnt+=1 if cnt>=idx and len(citations)-cnt