목록hash (7)
N
https://leetcode.com/problems/permutation-in-string/ Permutation in String - 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 HashMap을 이용. 문제는 풀었지만 시간이 간당간당하게 통과해서, 더 큰 문자열이 들어오면 다른 알고리즘을 써야할 것 같다. 투포인터를 이용한 문제인 것 같다. map을 선언해서 s1에 존재하는 모든 문자를 카운팅한다. 이후 s2를 순회하면서, map에 해당 문자가 있는지 확인..
https://leetcode.com/problems/snapshot-array/ Snapshot Array - 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 Map을 이용한 문제 풀이. 생성자가 호출될 때 전체 스냅샷이 저장될 snapshots(Map), 현재 스냅샷을 나타내는 array(Map), 현재 스냅 Id를 나타내는 snapId를 선언한다. set(index, val) 함수. 현재 스냅샷에 key: index, value: val 로 저장한다. sna..
811. Subdomain Visit Count A website domain "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com" and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly. A count-paired domain is a domain that has one o..
560. Subarray Sum Equals K Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k. Example 1: Input: nums = [1,1,1], k = 2 Output: 2 Example 2: Input: nums = [1,2,3], k = 3 Output: 2 Constraints: 1
https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - 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 Map을 활용한 문제 풀이. s의 각 문자부터 시작하면서 map을 선언한다. substring을 추출하는데, 중복되는 문자가 없어야 한다. 그렇기 때문에 이중 for문을 사용하여 substri..

해시 테이블(Hash Table) 키와 값을 받아 키를 해싱(Hashing)하여 나온 index 값을 저장하는 선형 자료구조. 삽입은 O(1)이며, 키를 알고 있다면 삭제와 탐색도 O(1)로 수행한다. 해시 함수를 통해 키를 특정 범위 내 숫자로 변경한다. 키로 "name"이 주어진다면, 컴퓨터에서는 해시 함수를 통해 1239593로 바꿔 데이터를 저장한다. 즉, 사람의 입장에서는 name이지만 컴퓨터의 입장에서는 1239539가 된다. value가 저장되는 공간을 bucket이라 한다. JavaScript에서 객체(Object)가 해시 테이블에 해당한다. 해시 충돌(Hash Collision) 만약 해시 함수의 결과가 기존에 있던 값과 같게 된다면 충돌이 발생한다. 이를 해결하기 위해서 "분리 연결법"..

옷의 모든 조합을 구하여 문제를 푸는 방식이다. 우선 맵을 이용하여 의상의 종류에 따른 개수를 구하였다. clothes[i][1]는 의상의 종류를 나타내므로 맵의 KEY 값이 된다. 그렇다면 해당하는 KEY의 값을 +1 씩 해주어서 종류에 따른 의상의 개수를 구하였다. 맵을 순회하면서 각각의 VALUE + 1 을 answer에 곱하여 마지막에는 answer - 1을 하여 반환해주면 된다. -1을 하는 이유는 모든 옷을 안입는 경우는 존재하지 않기 때문이다. 예를들어 옷의 종류가 A, B, C라고 하자. A 옷의 개수 : n(A) B 옷의 개수 : n(B) C 옷의 개수 : n(C) 그리고 해당 옷을 안입는 경우를 고려하여 각각 + 1을 해주도록 한다. 결국 (n(A) + 1) * (n(B) + 1) * ..