10 2018 档案
发表于 2018-10-31 18:32阅读:309评论:0推荐:0
摘要:Given a blacklist B containing unique integers from [0, N), write a function to return a uniform random integer from [0, N) which is NOT in B. Optimiz
阅读全文 »
发表于 2018-10-31 16:55阅读:247评论:0推荐:0
摘要:Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same. If possible, output
阅读全文 »
发表于 2018-10-30 22:39阅读:219评论:0推荐:0
摘要:Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string.
阅读全文 »
发表于 2018-10-30 22:24阅读:214评论:0推荐:0
摘要:Given two arrays, write a function to compute their intersection. Example 1: Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [9,4] Exam
阅读全文 »
发表于 2018-10-30 22:15阅读:183评论:0推荐:0
摘要:Given two arrays, write a function to compute their intersection. Example 1: Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [4,9] Exam
阅读全文 »
发表于 2018-10-30 21:53阅读:168评论:0推荐:0
摘要:Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Example 2: Note:You may assume the string contains only
阅读全文 »
发表于 2018-10-30 21:41阅读:189评论:0推荐:0
摘要:Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Example 1: Example 2: Note:You may assume all input has v
阅读全文 »
发表于 2018-10-30 15:53阅读:147评论:0推荐:0
摘要:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According
阅读全文 »
发表于 2018-10-30 09:47阅读:267评论:0推荐:0
摘要:Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [
阅读全文 »
发表于 2018-10-30 09:26阅读:200评论:0推荐:0
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Return 0 if the array contains less than 2 el
阅读全文 »
发表于 2018-10-29 19:05阅读:174评论:0推荐:0
摘要:Sort a linked list in O(n log n) time using constant space complexity. Example 1: Example 2: AC code: time(O(nlongn) space(O(logn)) Runtime: 28 ms, fa
阅读全文 »
发表于 2018-10-29 15:13阅读:150评论:0推荐:0
摘要:Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first elem
阅读全文 »
发表于 2018-10-28 21:45阅读:195评论:0推荐:0
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. Example: AC code: Runtime: 4 ms, faster tha
阅读全文 »
发表于 2018-10-28 21:00阅读:170评论:0推荐:0
摘要:Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: AC code: Runtime: 0 ms, faster than 100.00%
阅读全文 »
发表于 2018-10-28 17:58阅读:200评论:0推荐:0
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given a non-empty strin
阅读全文 »
发表于 2018-10-28 16:49阅读:297评论:0推荐:0
摘要:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not conta
阅读全文 »
发表于 2018-10-27 21:41阅读:187评论:0推荐:0
摘要:The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total num
阅读全文 »
发表于 2018-10-26 21:43阅读:123评论:0推荐:0
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and num
阅读全文 »
发表于 2018-10-26 21:24阅读:189评论:0推荐:0
摘要:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representati
阅读全文 »
发表于 2018-10-25 18:50阅读:171评论:0推荐:0
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the
阅读全文 »
发表于 2018-10-25 16:31阅读:154评论:0推荐:0
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: AC code: Runtime: 12 ms
阅读全文 »
发表于 2018-10-25 12:20阅读:169评论:0推荐:0
摘要:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist
阅读全文 »
发表于 2018-10-25 10:52阅读:148评论:0推荐:0
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Example 2: my code: Runtime: 12 ms, faster than
阅读全文 »
发表于 2018-10-24 18:07阅读:196评论:0推荐:0
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Example 2:
阅读全文 »
发表于 2018-10-24 17:36阅读:144评论:0推荐:0
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). Y
阅读全文 »
发表于 2018-10-24 16:39阅读:186评论:0推荐:0
摘要:Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra
阅读全文 »
发表于 2018-10-24 15:47阅读:224评论:0推荐:0
摘要:Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjac
阅读全文 »
发表于 2018-10-24 12:02阅读:168评论:0推荐:0
摘要:Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Exampl
阅读全文 »
发表于 2018-10-24 11:03阅读:277评论:0推荐:0
摘要:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. Example: AC code: Runtime: 88 ms, faster than 42.24% of C++
阅读全文 »
发表于 2018-10-23 22:17阅读:232评论:0推荐:0
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOB
阅读全文 »
发表于 2018-10-23 21:20阅读:170评论:0推荐:0
摘要:Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the or
阅读全文 »
发表于 2018-10-23 21:09阅读:174评论:0推荐:0
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f
阅读全文 »
发表于 2018-10-23 20:39阅读:176评论:0推荐:0
摘要:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output:
阅读全文 »
发表于 2018-10-22 22:23阅读:167评论:0推荐:0
摘要:Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations permitt
阅读全文 »
发表于 2018-10-22 21:37阅读:207评论:0推荐:0
摘要:Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"path = "/a/../../
阅读全文 »
发表于 2018-10-22 18:47阅读:175评论:0推荐:0
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl
阅读全文 »
发表于 2018-10-22 18:30阅读:238评论:0推荐:0
摘要:Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an in
阅读全文 »
发表于 2018-10-22 18:10阅读:154评论:0推荐:0
摘要:Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justif
阅读全文 »
发表于 2018-10-21 19:27阅读:193评论:0推荐:0
摘要:Validate if a given string can be interpreted as a decimal number. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true"
阅读全文 »
发表于 2018-10-21 13:58阅读:156评论:0推荐:0
摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
阅读全文 »
发表于 2018-10-21 13:40阅读:173评论:0推荐:0
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p
阅读全文 »
发表于 2018-10-20 22:24阅读:192评论:0推荐:0
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p
阅读全文 »
发表于 2018-10-20 21:36阅读:179评论:0推荐:0
摘要:Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->
阅读全文 »
发表于 2018-10-20 10:35阅读:148评论:0推荐:0
摘要:The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following seque
阅读全文 »
发表于 2018-10-19 21:04阅读:161评论:0推荐:0
摘要:Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: AC code: Runtime: 0 ms, faster than 1
阅读全文 »
发表于 2018-10-19 20:36阅读:158评论:0推荐:0
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia
阅读全文 »
发表于 2018-10-19 20:27阅读:162评论:0推荐:0
摘要:Given a collection of intervals, merge all overlapping intervals. Example 1: Example 2: AC code:
阅读全文 »
发表于 2018-10-19 16:00阅读:130评论:0推荐:0
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word
阅读全文 »
发表于 2018-10-19 09:40阅读:152评论:0推荐:0
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文 »
发表于 2018-10-18 22:33阅读:172评论:0推荐:0
摘要:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Inpu
阅读全文 »
发表于 2018-10-18 22:16阅读:173评论:0推荐:0
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return the
阅读全文 »
发表于 2018-10-18 22:11阅读:150评论:0推荐:0
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all
阅读全文 »
发表于 2018-10-17 22:00阅读:224评论:0推荐:0
摘要:Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Example 2: Example 3: Note: -100.0 < x < 100.0 n is a 32-bit signed int
阅读全文 »
发表于 2018-10-17 21:38阅读:162评论:0推荐:0
摘要:Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat",
阅读全文 »
发表于 2018-10-17 20:01阅读:178评论:0推荐:0
摘要:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which
阅读全文 »
发表于 2018-10-17 19:46阅读:185评论:0推荐:0
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: AC code: Runtime: 28 ms, faster than 46
阅读全文 »
发表于 2018-10-17 11:50阅读:182评论:0推荐:0
摘要:Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,
阅读全文 »
发表于 2018-10-17 11:17阅读:175评论:0推荐:0
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文 »
发表于 2018-10-16 20:37阅读:172评论:0推荐:0
摘要:Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. '*' M
阅读全文 »
发表于 2018-10-16 20:03阅读:148评论:0推荐:0
摘要:Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Example 1: Ex
阅读全文 »
发表于 2018-10-16 17:35阅读:173评论:0推荐:0
摘要:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
阅读全文 »
发表于 2018-10-16 16:59阅读:187评论:0推荐:0
摘要:Given an unsorted integer array, find the smallest missing positive integer. Given an unsorted integer array, find the smallest missing positive integ
阅读全文 »
发表于 2018-10-15 22:00阅读:184评论:0推荐:0
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb
阅读全文 »
发表于 2018-10-15 21:30阅读:196评论:0推荐:0
摘要:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the
阅读全文 »
发表于 2018-10-14 17:38阅读:217评论:0推荐:0
摘要:The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "on
阅读全文 »
发表于 2018-10-14 16:47阅读:197评论:0推荐:0
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9
阅读全文 »
发表于 2018-10-11 22:28阅读:195评论:0推荐:0
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Y
阅读全文 »
发表于 2018-10-10 23:18阅读:185评论:0推荐:0
摘要:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. Example 1: Exampl
阅读全文 »
发表于 2018-10-09 23:44阅读:197评论:0推荐:0
摘要:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conca
阅读全文 »
发表于 2018-10-09 08:35阅读:163评论:0推荐:0
摘要:Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list t
阅读全文 »
发表于 2018-10-08 21:57阅读:184评论:0推荐:0
摘要:Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividi
阅读全文 »
发表于 2018-10-07 22:39阅读:200评论:0推荐:0
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to
阅读全文 »
发表于 2018-10-06 22:03阅读:262评论:0推荐:0
摘要:origianl For the past few days, I’ve been reading various explanations of the Knuth-Morris-Pratt string searching algorithms. For some reason, none of
阅读全文 »
发表于 2018-10-06 21:38阅读:181评论:0推荐:0
摘要:Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Example 2: Cla
阅读全文 »
发表于 2018-10-06 21:17阅读:204评论:0推荐:0
摘要:Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another ar
阅读全文 »
发表于 2018-10-06 21:12阅读:179评论:0推荐:0
摘要:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra spa
阅读全文 »
发表于 2018-10-05 21:52阅读:174评论:0推荐:0
摘要:Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no
阅读全文 »
发表于 2018-10-05 21:07阅读:119评论:0推荐:0
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: AC code: Runtime: 56 ms, faster than 26.25
阅读全文 »
发表于 2018-10-04 10:43阅读:185评论:0推荐:0
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: A
阅读全文 »
发表于 2018-10-04 09:57阅读:207评论:0推荐:0
摘要:Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比较慢. assign() 给list赋值 back() 返回最后一个元素 begin() 返回指向第一个元素的迭代器 clear() 删除所有元素 empty() 如果list是空的则返回
阅读全文 »
发表于 2018-10-04 09:54阅读:147评论:0推荐:0
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example:
阅读全文 »
发表于 2018-10-03 22:08阅读:147评论:0推荐:0
摘要:Given a linked list, remove the n-th node from the end of list and return its head. Example: Note: Given n will always be valid. Follow up: Could you
阅读全文 »
发表于 2018-10-03 21:11阅读:218评论:0推荐:0
摘要:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to le
阅读全文 »
发表于 2018-10-02 22:41阅读:143评论:0推荐:0
摘要:Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique q
阅读全文 »
发表于 2018-10-02 22:02阅读:150评论:0推荐:0
摘要:Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the thr
阅读全文 »