코딩테스트 기록/08. TIL 3

코딩테스트 정렬에 관하여 정리 (Java)

1. primitive type(원시 자료형) 배열의 정렬과 Wrapper Class배열의 정렬은 다르다. 예시를 살펴봅시다. BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int[] arr = new int[N]; for(int i = 0; i < N; i++){ arr[i] = Integer.parseInt(br.readLine()); } Arrays.sort(arr); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); for(int i = 0; i < N; ..

코딩테스트 기본 자료구조(Python) - 딕셔너리

✍학습 키워드 딕셔너리? 사전이라는 의미이며, 데이터를 키(key) : 값(value) 형식으로 저장할 수 있는 자료구조이다. 키 값은 immutable 객체 타입이 와야한다. 키 값은 중복될 수 없다. 동일한 키를 추가하면 기존의 키와 값이 나중에 추가된 키와 값으로 변경된다( 이건 몰랐지! ) 📝새로 배운 개념 활용법 딕셔너리 values의 합 구하기 D = dict() for each in lists: D[each] = 23 answer = sum(D.values()) # value의 값이 합쳐서 리턴된다. 딕셔너리 정렬방법 # 1. sorted와 items() 이용 D = dict() D1 = dict(sorted(D.items())) #2. 람다 이용 answer = list(D.items())..

파이썬 코테 라이브러리 정리

✍학습 키워드 1. itertools 라이브러리 ⇒ 순열과 조합을 쉽게 구현할 수 있는 라이브러리. from itertools import permutations x = ['a', 'b', 'c'] y = list(permutations(x, 2)) print(y) #[('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b')] permutations 함수는 ‘a’, ‘b’, ‘c’에서 2개를 뽑아 나열하는 모든 순열을 리턴해준다. from itertools import combinations x = ['a', 'b', 'c'] y = list(combinations(x, 2)) #[('a', 'b'), ('a', 'c'), ('b', ..