LeetCode
文章平均质量分 61
winghare
学习中,多多包涵
展开
-
【LeetCode】136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2016-01-18 17:51:39 · 276 阅读 · 0 评论 -
【LeetCode】357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [11,22,33,44,原创 2016-06-18 20:10:31 · 253 阅读 · 0 评论 -
【LeetCode】319. Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off原创 2016-06-19 16:19:57 · 209 阅读 · 0 评论 -
【LeetCode】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, ret原创 2016-06-20 15:12:29 · 287 阅读 · 0 评论 -
【LeetCode】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 / 3return [1,3,2].Note: Recursive solu原创 2016-06-20 16:00:45 · 193 阅读 · 0 评论 -
【LeetCode】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 case le原创 2016-07-18 15:41:31 · 238 阅读 · 0 评论 -
【LeetCode】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原创 2016-07-21 10:04:47 · 245 阅读 · 0 评论 -
【LeetCode】337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour原创 2016-07-21 19:38:39 · 272 阅读 · 0 评论 -
【LeetCode】108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.class Solution {public: TreeNode* build(vector& nums, int left, int right) { if (left >原创 2016-08-01 16:45:01 · 244 阅读 · 0 评论 -
【LeetCode】347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number原创 2016-06-15 22:25:31 · 216 阅读 · 0 评论 -
【LeetCode】122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2016-06-14 20:44:54 · 212 阅读 · 0 评论 -
【LeetCode】137. Single Number II
137. Single Number IIGiven an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could y原创 2016-01-23 14:18:08 · 351 阅读 · 0 评论 -
【LeetCode】169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2016-01-31 11:36:40 · 257 阅读 · 0 评论 -
【LeetCode】144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution i原创 2016-02-02 10:17:35 · 312 阅读 · 0 评论 -
【LeetCode】338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2016-05-27 10:26:06 · 193 阅读 · 0 评论 -
【LeetCode】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原创 2016-05-30 11:51:09 · 280 阅读 · 0 评论 -
【LeetCode】96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2016-05-30 15:33:02 · 211 阅读 · 0 评论 -
【LeetCode】268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho原创 2016-05-31 16:20:45 · 230 阅读 · 0 评论 -
【LeetCode】260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given原创 2016-06-14 11:39:38 · 230 阅读 · 0 评论 -
【LeetCode】377. Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The pos原创 2016-08-06 10:25:59 · 274 阅读 · 0 评论