본문 바로가기

leetcode73

[LeetCode][Kotlin] 706. Design HashMap 706. Design HashMapDesign a HashMap without using any built-in hash table libraries. Implement the MyHashMap class:MyHashMap() initializes the object with an empty map.void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.int get(int key) returns the value to which the specified key is mapped, or -1 if this.. 2024. 8. 16.
[LeetCode][Kotlin] 705. Design HashSet 705. Design HashSetDesign a HashSet without using any built-in hash table libraries. Implement MyHashSet class:void add(key) Inserts the value key into the HashSet.bool contains(key) Returns whether the value key exists in the HashSet or not.void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.내장된 해시 테이블 라이브러리를 사용하지 않고 HashSet을 디자인합니다.MyHashSet .. 2024. 8. 16.
[LeetCode][Kotlin] 448. Find All Numbers Disappeared in an Array 448. Find All Numbers Disappeared in an ArrayGiven an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.nums[i]가 [1, n] 범위에 있는 n개의 정수로 구성된 배열이 주어지면, nums에 나타나지 않는 [1, n] 범위의 모든 정수 배열을 반환합니다. Example 1:Input: nums = [4,3,2,7,8,2,3,1]Output: [5,6] Example 2:Input: nums = [1,1]Output: [2] Constraints:n =.. 2024. 8. 16.
[LeetCode][Kotlin] 496. Next Greater Element I 496. Next Greater Element IThe next greater element of some element x in an array is the first greater element that is to the right of x in the same array.You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2. For each 0 next greater element of nums2[j] in nums2. If there is no next greater element, then the answer for this query is -1. Return an a.. 2024. 8. 14.
[LeetCode][Kotlin] 169. Majority Element 169. Majority ElementGiven an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.크기 n의 배열 num이 주어지면 대부분의 요소를 반환합니다. 다수 요소는 ⌊n/2⌋회 이상 나타나는 요소입니다. 대부분의 요소가 배열에 항상 존재한다고 가정할 수 있습니다. Example 1:Input: nums = [3,2,3]Output: 3 Example 2:Input: nums = [2,2,1,1,1,2.. 2024. 8. 14.
[LeetCode][Kotlin] 605. Can Place Flowers 605. Can Place FlowersYou have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false ot.. 2024. 8. 14.
[LeetCode][Kotlin] 118. Pascal's Triangle 118. Pascal's TriangleGiven an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:정수 numRows가 주어지면 Pascal의 삼각형의 첫 번째 numRows를 반환합니다. Pascal의 삼각형에서 각 숫자는 표시된 대로 바로 위에 있는 두 숫자의 합입니다.  Example 1:Input: numRows = 5Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] Example 2:Input: numRows = 1Output.. 2024. 8. 13.