파이썬 알고리즘 : 신고 결과 받기

2023년 11월 13일 알고리즘 문제풀이 문제 신고 결과 받기 난이도 Lv.1 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 def solution(id_list, report, k): n = len(id_list) answer = [0 for _ in range(n)] table = [[0 for _ in range(n)] for _ in range(n)] for x in report: sender, receiver = x.split() a = id_list.index(sender) b = id_list.index(receiver) table[b][a] = 1 for i in table: if sum(i) >= k: for j in range(len(i)): if i[j]: answer[j] += 1 return answer 어떤 배열들을 만들어야 하는지 헷갈렸지만 크게 어려운 문제는 아니었다. ...

2023년 11월 13일 · 1 분 · 배준수

배열과 튜플

Arrays in Typescript Typed Arrays : 원소들이 동일한 타입의 값인 것 annotation 없어도 존재하는 원소들을 보고 inference 한다. 빈 배열은 inference할 수 없으므로 any타입이 된다. 1 2 3 4 5 6 7 8 // type annotation const carMarkers: string[] = ['ford', 'toyota', 'chevy']; // Date[] 타입으로 inference const dates = [new Date(), new Date()]; // 2차원. string[][] type이다. const carsByMake = [['f150'], ['corolla'], ['camaro']]; 특징 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // 배열에서 추출시 type inference 한다. const car = carMakers[0]; // string type const myCar = carMakers.pop(); // string type // 배열에 동일하지 않은 type의 값은 추가할 수 없다. carMakers.push(100); // string[]에 number를 넣으면 오류 발생 // 'map, 'forEach', 'reduce' 사용 carMakers.map((car: string): string => { return car.toUpeerCase(); }); // 다수의 type 사용. // const importantDates: (string | Date)[]로 inference 된다. const importantDates = [new Date(), '2030-10-10']; // annotation const importanteDates: (Date | string)[] = [new Date()]; Tuple 각 원소가 기록의 속성을 나타내는 배열과 같은 구조 ...

2023년 10월 4일 · 2 분 · 배준수