본문 바로가기

IT/알고리즘73

[Leetcode]706. Design HashMap Design HashMap - LeetCode Design HashMap - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 해쉬맵을 디자인 하는 방법은 총 2가지 방법이 있다. 개별 체이닝 - 충돌 발생시 연결리스트로 연결 오픈 어드레싱 - 충돌발생시 테이블 공간내 빈공간을 찾아 해결 아래 풀이는 개별체이닝을 이용해 해결한 방법이다. import collections class ListNode(object): def __init__(self,key = None,.. 2020. 10. 7.
[Leetcode]706. Design HashMap Design HashMap - LeetCode Design HashMap - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 해쉬맵을 디자인 하는 방법은 총 2가지 방법이 있다. 개별 체이닝 - 충돌 발생시 연결리스트로 연결 오픈 어드레싱 - 충돌발생시 테이블 공간내 빈공간을 찾아 해결 아래 풀이는 개별체이닝을 이용해 해결한 방법이다. import collections class ListNode(object): def __init__(self,key = None,.. 2020. 10. 7.
[BOJ]1874.스택 수열 1874번: 스택 수열 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net 처음에 무한루프를 걸고 탈출하는 방식으로 문제를 해결하려고 했는데 그렇게 되면 NO를 출력시키는 부분의 예외처리를 해줄 수 없었다. 그래서 while 문에 조건문을 넣고 cnt가 num 이상이 될 때 까지 증가시킬 때 까지 반복했다. 만약 반복문을 탈출했을 때 stack 의 top이 num아니라면 NO를 출력시켜줘야한다. 풀이 n = int(input()) .. 2020. 10. 7.
[Leetcode]23. Merge k Sorted Lists Merge k Sorted Lists - LeetCode 풀이 1 가장 먼저 쉬운 방법인 리스트에 모든 연결리스트를 순회하여 저장 후 정렬한 다음 다시 리스트로 만들어 리턴해주는 방법으로 해결했다. from typing import List class ListNode: def __init__(self,val = 0, next = None): self.val = val self.next = next class Solution: def mergeKLists(self,lists:List[ListNode])->ListNode: data = [] for list in lists: while list: data.append(list.val) list = list.next data = sorted(data) root.. 2020. 10. 6.