python3 27

[프로그래머스] LEVEL 1 문자열 내 마음대로 정렬하기, python3

import collections def solution(strings, n): answer = [] cp_str=[] len_str=len(strings) for i in range(len_str): cp_str.append(strings[i][n]) cp_str.sort() # 인덱스 값끼리 정렬 cp_str=list(collections.Counter(cp_str).keys()) # 중복값 제거 for i in range(len(cp_str)): cnt=0 ex=[] # 인덱스 값이 중복되는 strings 저장 for j in range(len_str): if strings[j][n]==cp_str[i]: # strings의 n번째와 cp_str이 같으면 ex에 추가 cnt+=1 ex.append(..

STUDY/Algorithm 2019.10.16

[프로그래머스] LEVEL1 체육복, python3

내가 짠 코드 def solution(n, lost, reserve): for i in range(len(reserve)): if lost.count(reserve[i]): lost.remove(reserve[i]) reserve[i]=-1; #비교는 하되 못빌려주는 값으로 바꿈 for i in range(len(reserve)): tmp_rsv= reserve.pop() if tmp_rsv==-1: # 값이 -1일때는 비교 안함 continue if lost.count(tmp_rsv+1): lost.remove(tmp_rsv+1) elif lost.count(tmp_rsv-1): lost.remove(tmp_rsv-1) answer = n-len(lost) return answer _reserve = ..

STUDY/Algorithm 2019.10.15