B
文章平均质量分 75
LQCUN
这个作者很懒,什么都没留下…
展开
-
526. Beautiful Arrangement
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <=...原创 2018-02-09 11:43:34 · 148 阅读 · 0 评论 -
382. Linked List Random Node
Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the linked list is extremely large and its len...原创 2018-02-17 12:50:48 · 103 阅读 · 0 评论 -
646. Maximum Length of Pair Chain
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b < c. Chain of...原创 2018-02-17 15:58:26 · 95 阅读 · 0 评论 -
22. Generate Parentheses
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:[ "((()))", "(()())", "(())()", "()(())", "...原创 2018-02-17 16:55:45 · 107 阅读 · 0 评论 -
697. Degree of an Array
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length of a (c...原创 2018-02-19 10:42:37 · 202 阅读 · 0 评论 -
46. Permutations
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] 思路:递归。...转载 2018-02-20 00:28:47 · 98 阅读 · 0 评论 -
343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return ...原创 2018-02-20 09:58:37 · 117 阅读 · 0 评论 -
447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tu...原创 2018-02-20 12:24:55 · 96 阅读 · 0 评论 -
498. Diagonal Traverse
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example:Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Outpu...原创 2018-02-21 22:50:53 · 130 阅读 · 0 评论 -
445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return i...原创 2018-02-21 23:38:01 · 98 阅读 · 0 评论 -
481. Magical String
A magical string S consists of only '1' and '2' and obeys the following rules:The string S is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the...原创 2018-02-22 13:23:53 · 116 阅读 · 0 评论 -
318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower ca...原创 2018-02-22 13:36:20 · 131 阅读 · 0 评论 -
378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not the...原创 2018-02-22 13:59:41 · 118 阅读 · 0 评论 -
230. Kth Smallest Element in a BST
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 total elements.Follow up:What if the BST is modifi...原创 2018-02-22 14:40:06 · 128 阅读 · 0 评论 -
454. 4Sum II
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same length ...原创 2018-02-16 21:56:00 · 250 阅读 · 0 评论 -
421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.Could you do this in O(n) runtime?Example:Input: [3, 10, 5, ...原创 2018-02-16 21:41:51 · 116 阅读 · 0 评论 -
667. Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, ... , a...原创 2018-02-11 12:52:37 · 140 阅读 · 0 评论 -
451. Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must...原创 2018-02-11 13:28:27 · 98 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Could yo...原创 2018-02-11 13:49:27 · 101 阅读 · 0 评论 -
669. Trim a Binary Search Tree
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the resu原创 2018-02-06 11:01:19 · 103 阅读 · 0 评论 -
696. Count Binary Substrings
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. Substrin...原创 2018-02-11 15:45:03 · 118 阅读 · 0 评论 -
238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).F...原创 2018-02-11 22:52:12 · 109 阅读 · 0 评论 -
565. Array Nesting
A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.Suppose ...原创 2018-02-12 13:27:22 · 108 阅读 · 0 评论 -
538. Convert BST to Greater Tree
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Example:...原创 2018-02-12 14:48:10 · 101 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2].Note: Recursive solution is trivial, could...原创 2018-02-12 14:54:26 · 116 阅读 · 0 评论 -
672. Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of sta...原创 2018-02-13 13:00:16 · 138 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input: [1,2,3] Output: ...原创 2018-02-16 14:22:21 · 93 阅读 · 0 评论 -
503. Next Greater Element II
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first gre...原创 2018-02-16 16:53:48 · 107 阅读 · 0 评论 -
328. 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 pla...原创 2018-02-23 15:46:36 · 129 阅读 · 0 评论