随笔分类 - LeetCode
摘要:Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two. Example 1: Example 2: Example 3: 这道题让我们判断一个数是否为2的次方数,而且要求时间和空间复杂度都为常数,那么对于这种玩
阅读全文
摘要:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Exampl
阅读全文
摘要:Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output:
阅读全文
摘要:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The algorithm should run in linear time and in O(1) spa
阅读全文
摘要:You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list
阅读全文
摘要:Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return
阅读全文
摘要:Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Exampl
阅读全文
摘要:Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". Update (2015-02-12): For C
阅读全文
摘要:Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Example 2: Credits:Special thanks to @jianchao.li.fighte
阅读全文
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negativeintegers, +, -, *, / operators an
阅读全文
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the
阅读全文
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Example 1: Example 2: 这道题给了我们一堆二维点,然后让求最大的共线点的个数,根
阅读全文
摘要:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is
阅读全文
摘要:There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following re
阅读全文
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by thi...
阅读全文
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or
阅读全文
摘要:Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. to
阅读全文
摘要:Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia:In a complete binary tree every lev
阅读全文