본문 바로가기

알고리즘10

소수구하기/ 소수판별 [Algorithm] 에라토스테네스의 체 - C++ https://donggoolosori.github.io/2020/10/16/eratos/ [Algorithm] 에라토스테네스의 체 - C++ - DGOS | 동꿀오소리 에라토스테네스의 체는 소수(Prime Number) 를 찾는 방법이다. 대량의 소수들을 구해야할 때 아주 유용한 알고리즘으로 O(N^1/2)의 시간복잡도를 갖는다. donggoolosori.github.io [이것이 코딩 테스트다 with Python] 37강 소수 판별 알고리즘 https://freedeveloper.tistory.com/391 [이것이 코딩 테스트다 with Python] 37강 소수 판별 알고리즘 https://www.youtube.com/watch?v=CyINCm.. 2022. 7. 2.
사각배열을 만들어 출력하는 경우 def solution(n): array = [[0 for j in range(n)] for i in range(n)] # 1 result = [] startRow, endRow = 0, len(array) - 1 startCol, endCol = 0, len(array[0]) - 1 count=0 while startRow 2022. 7. 2.
우선순위큐(최소힙) 우선순위큐: https://www.daleseo.com/python-heapq/ [파이썬] heapq 모듈 사용법 Engineering Blog by Dale Seo www.daleseo.com https://velog.io/@t1won/Python-heapq#예제-4---최소-힙에서-최대값-삭제하기 [Python] heapq \[파이썬] heapq 모듈 사용법 velog.io 2022. 7. 2.
커스텀 정렬(파이썬) import functools def comparator(a,b): t1 = a+b t2 = b+a return (int(t1) > int(t2)) - (int(t1) < int(t2)) # t1이 크다면 1 // t2가 크다면 -1 // 같으면 0 def solution(numbers): n = [str(x) for x in numbers] #또는, n = list(map(str, numbers)) n = sorted(n, key=functools.cmp_to_key(comparator), reverse=True) answer = str(int(''.join(n))) # 0000의 경우에는 0으로 출력하려면 int하고 str으로 다시 변환해야 해요 return answer print(solution([.. 2022. 7. 2.