전체 글

    May LeetCoding Challenge[Day19] - Online Stock Span

    Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock's price for the current day. The span of the stock's price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today's price. For example, if the price of a stock over the next 7..

    May LeetCoding Challenge[Day18] - Permutation in String

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string. Input: s1 = "ab" s2 = "eidbaooo" Output: True Explanation: s2 contains one permutation of s1 ("ba"). 1. 알고리즘을 해결하기 위해서 생각한 방법 - 해당 문제는 s1의 짧은 문자열과 s2의 긴 문자열이 있을 때, anagram이 성립되면 true, 그렇지 않으면 flase를 반환 값으로..

    May LeetCoding Challenge[Day17] - Find All Anagrams in a String

    Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100. The order of output does not matter. Input: s: "cbaebabacd" p: "abc" Output: [0, 6] Explanation: The substring with start index = 0 is "cba", which is an anagram of "abc". The substrin..

    May LeetCoding Challenge[Day16] - Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity. The relative order inside both the even and odd groups should remain as it was in the input. The first node is cons..

    May LeetCoding Challenge[Day15] - Maximum Sum Circular Subarray

    Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning of the array. (Formally, C[i] = A[i] when 0 = 0.) Also, a subarray may only include each element of the fixed buffer A at most once. (Formally, for a subarray C[i], C[i+1], ..., C[j], there does not exist i

    May LeetCoding Challenge[Day14] - Implement Trie (Prefix Tree)

    Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z.All inputs are guaranteed to be non-empty strings. Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // returns true trie.search("app"); // returns false trie.startsWith("app"); // returns true trie.insert("app"); trie.search("app"); // returns..

    May LeetCoding Challenge[Day13] - Remove K Digits

    Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: - The length of num is less than 10002 and will be ≥ k. - The given num does not contain any leading zero. Input: num = "1432219", k = 3 Output: "1219" Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest. 1..

    May LeetCoding Challenge[Day12] - Single Element in a Sorted Array

    You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once. Input: [3,3,7,7,10,11,11] Output: 10 1. 알고리즘을 해결하기 위해서 생각한 방법 - 쉬어가는 날인가보다. - 배열이 주어질 때, 배열 중에서 혼자 짝이 되지 않는 숫자를 찾는 문제이다. - 2020/04/20 - [내 맘대로 알고리즘] - LeetCode[day1] - Single Number - 4월에 첫 번째, Sing..