LeetCode

    [LeetCode] 108. Convert Sorted Array to Binary Search Tree

    [LeetCode] 108. Convert Sorted Array to Binary Search Tree

    108. Convert Sorted Array to Binary Search Tree Easy 7274385Add to ListShare Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. Example 1: Input: nums = [-10,-3,0,5,9] Output: [0,-3,9,-10..

    [LeetCode] 621. Task Scheduler

    621. Task Scheduler Medium Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non-negative integer n that represents the cooldown period between two same ta..

    [LeetCode] 916. Word Subsets

    916. Word Subsets Medium You are given two string arrays words1 and words2. A string b is a subset of string a if every letter in b occurs in a including multiplicity. For example, "wrr" is a subset of "warrior" but is not a subset of "world". A string a from words1 is universal if for every string b in words2, b is a subset of a. Return an array of all the universal strings in words1. You may r..

    [LeetCode] 251. Flatten 2D Vector

    251. Flatten 2D Vector Medium 602338Add to ListShare Design an iterator to flatten a 2D vector. It should support the next and hasNext operations. Implement the Vector2D class: Vector2D(int[][] vec) initializes the object with the 2D vector vec. next() returns the next element from the 2D vector and moves the pointer one step forward. You may assume that all the calls to next are valid. hasNext(..

    [LeetCode] 890. Find and Replace Pattern

    890. Find and Replace Pattern Medium 2584138Add to ListShare Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order. A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word. Recall that a permutation of letters is..

    [LeedCode] 929. Unique Email Addresses 파이썬 (Easy)

    문제 929. Unique Email Addresses Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'. For example, in "alice@leetcode.com", "alice" is the local name, and "leetcode.com" is the domain name. If you add periods '.' between some characters in the local name part of an email address, mail sent ..

    [LeetCode/릿코드] - 10. Regular Expression Matching - (Hard/하드)

    문제 : Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: '.' Matches any single character.​​​​ '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). 문제 해설 : 이번 문제는 어려워서,, 다른 코드를 조금 참고 했다. Dynamic Programming / Recursion 으로 풀 수 있는데, 처음에 구현 문제라고 생각한 것이 문제였다. 주어지는 문자열 s 와 p 가..

    [LeetCode/릿코드] - 4. Median of Two Sorted Arrays - (Hard/하드)

    문제 Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 문제 설명 : 두 개의 리스트가 주어진다. 각 리스트는 크기가 다르며 두 개의 리스트의 모든 값들 중에서 중간 값을 반환해야 한다. 시간 복잡도는 O(log (m+n)) 이어야 한다. 아이디어 : 1. 시간 복잡도와 데이터 제한을 봤을때, 반복문으로 문제를 풀 수 없다. 2. 중간 값을 구하려면, 모든 값의 상태를 알아야 하기 때문에 sort를 사용했다. 최악의 경우 O(NlogN) 3. 시간복잡도도..