leetcode
文章平均质量分 71
小榕流光
这个作者很懒,什么都没留下…
展开
-
[leetcode] 278. First Bad Version 解题报告
题目链接:https://leetcode.com/problems/first-bad-version/You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the原创 2015-12-28 16:19:27 · 766 阅读 · 0 评论 -
[leetcode] 292. Nim Game 解题报告
题目链接:https://leetcode.com/problems/nim-game/You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston原创 2015-12-29 17:29:37 · 692 阅读 · 1 评论 -
[leetcode] 136. Single Number 解题报告
题目链接:https://leetcode.com/problems/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 runti原创 2015-12-30 02:51:24 · 493 阅读 · 0 评论 -
[leetcode] 74. Search a 2D Matrix 解题报告
题目链接:https://leetcode.com/problems/search-a-2d-matrix/Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each原创 2016-01-02 08:48:44 · 925 阅读 · 0 评论 -
[leetcode] 35. Search Insert Position 解题报告
题目链接:https://leetcode.com/problems/search-insert-position/Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were原创 2016-01-02 11:34:37 · 393 阅读 · 0 评论 -
[leetcode] 83. Remove Duplicates from Sorted List 解题报告
题目连接:https://leetcode.com/problems/remove-duplicates-from-sorted-list/Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, r原创 2015-12-27 16:10:19 · 392 阅读 · 0 评论 -
[leetcode] 303. Range Sum Query - Immutable 解题报告
题目链接:https://leetcode.com/problems/range-sum-query-immutable/Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2原创 2015-12-22 05:02:04 · 488 阅读 · 0 评论 -
[leetcode] 238. Product of Array Except Self 解题报告
题目链接:https://leetcode.com/problems/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原创 2015-12-22 16:19:46 · 873 阅读 · 2 评论 -
[leetcode] 240. Search a 2D Matrix II 解题报告
题目链接:https://leetcode.com/problems/search-a-2d-matrix-ii/Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in e原创 2016-01-23 14:36:52 · 659 阅读 · 0 评论 -
[leetcode] 206. Reverse Linked List 解题报告
题目链接:https://leetcode.com/problems/reverse-linked-list/Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could原创 2016-01-07 11:17:33 · 505 阅读 · 0 评论 -
[leetcode] 203. Remove Linked List Elements 解题报告
题目链接:https://leetcode.com/problems/remove-linked-list-elements/Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, v原创 2016-01-07 13:53:23 · 415 阅读 · 0 评论 -
[leetcode] 198. House Robber 解题报告
题目链接:https://leetcode.com/problems/house-robber/You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stoppin原创 2015-12-23 11:42:35 · 528 阅读 · 0 评论 -
[leetcode] 147. Insertion Sort List 解题报告
题目链接:https://leetcode.com/problems/insertion-sort-list/Sort a linked list using insertion sort.思路:我发现自从用了虚拟头结点之后刷链表简直是毫无阻碍,哈哈!!代码如下:/** * Definition for singly-linked list. * struct Li原创 2016-01-07 15:48:06 · 471 阅读 · 0 评论 -
[leetcode] 141. Linked List Cycle 解题报告
题目链接:https://leetcode.com/problems/linked-list-cycle/Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:用快慢指针,慢的一次走一步,快的一次走两原创 2016-01-07 15:55:45 · 376 阅读 · 0 评论 -
[leetcode] 24. Swap Nodes in Pairs 解题报告
题目链接:https://leetcode.com/problems/swap-nodes-in-pairs/Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2-原创 2016-01-07 16:11:20 · 410 阅读 · 0 评论 -
[leetcode] 104. Maximum Depth of Binary Tree 解题报告
题目链接:https://leetcode.com/problems/maximum-depth-of-binary-tree/Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node原创 2015-12-24 17:45:41 · 340 阅读 · 0 评论 -
[leetcode] 108. Convert Sorted Array to Binary Search Tree 解题报告
题目链接:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:前面有一题将有序链表转换原创 2016-01-11 10:56:13 · 504 阅读 · 0 评论 -
[leetcode] 144. Binary Tree Preorder Traversal 解题报告
题目链接:https://leetcode.com/problems/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原创 2016-01-11 11:28:28 · 485 阅读 · 0 评论 -
[leetcode] 236. Lowest Common Ancestor of a Binary Tree 解题报告
题目链接:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the defin原创 2016-01-12 12:03:57 · 1051 阅读 · 0 评论 -
[leetcode] 145. Binary Tree Postorder Traversal 解题报告
题目链接:https://leetcode.com/problems/binary-tree-postorder-traversal/Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1原创 2016-01-12 14:24:55 · 558 阅读 · 1 评论 -
[leetcode] 117. Populating Next Right Pointers in Each Node II 解题报告
题目链接:https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any bina原创 2016-01-13 06:36:40 · 1861 阅读 · 0 评论 -
[leetcode] 150. Evaluate Reverse Polish Notation 解题报告
题目链接:https://leetcode.com/problems/evaluate-reverse-polish-notation/Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand m原创 2016-01-18 11:58:32 · 535 阅读 · 0 评论 -
[leetcode] 66. Plus One 解题报告
题目链接:https://leetcode.com/problems/plus-one/Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit i原创 2015-12-27 11:13:53 · 576 阅读 · 0 评论 -
[leetcode] 19. Remove Nth Node From End of List 解题报告
题目链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2原创 2015-12-28 09:58:15 · 378 阅读 · 0 评论 -
[leetcode] 58. Length of Last Word 解题报告
题目连接:https://leetcode.com/problems/length-of-last-word/Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.原创 2015-12-27 16:26:37 · 393 阅读 · 0 评论 -
[leetcode] 189. Rotate Array 解题报告
题目链接:https://leetcode.com/problems/rotate-array/Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,原创 2016-02-13 18:30:57 · 580 阅读 · 0 评论 -
[leetcode] 75. Sort Colors 解题报告
题目链接:https://leetcode.com/problems/sort-colors/Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order re原创 2015-12-30 17:30:15 · 634 阅读 · 0 评论 -
[leetcode] 319. Bulb Switcher 解题报告
题目链接:https://leetcode.com/problems/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 e原创 2016-01-14 14:59:44 · 494 阅读 · 0 评论 -
[leetcode] 232. Implement Queue using Stacks 解题报告
题目链接:https://leetcode.com/problems/implement-queue-using-stacks/Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the原创 2015-12-29 12:25:42 · 496 阅读 · 0 评论 -
[leetcode] 265. Paint House II 解题报告
题目链接:https://leetcode.com/problems/paint-house-ii/here are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is differen原创 2016-03-05 12:50:21 · 3428 阅读 · 0 评论 -
[leetcode] 334. Increasing Triplet Subsequence 解题报告
题目链接:https://leetcode.com/problems/increasing-triplet-subsequence/Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the functio原创 2016-02-19 13:14:48 · 1817 阅读 · 0 评论 -
[leetcode] 173. Binary Search Tree Iterator 解题报告
题目链接:https://leetcode.com/problems/binary-search-tree-iterator/Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling ne原创 2016-01-12 01:29:50 · 2239 阅读 · 0 评论 -
[leetcode] 328. Odd Even Linked List 解题报告
题目链接:https://leetcode.com/problems/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原创 2016-02-20 00:14:03 · 598 阅读 · 0 评论 -
[leetcode] 31. Next Permutation 解题报告
题目链接:https://leetcode.com/problems/next-permutation/Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is原创 2016-01-02 10:13:00 · 541 阅读 · 0 评论 -
[leetcode] 47. Permutations II 解题报告
题目链接:https://leetcode.com/problems/permutations-ii/Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the followi原创 2016-02-21 11:42:58 · 447 阅读 · 0 评论 -
[leetcode] 339. Nested List Weight Sum 解题报告
题目链接: https://leetcode.com/problems/nested-list-weight-sum/Given a nested list of integers, return the sum of all integers in the list weighted by their depth.Each element is either an integ原创 2016-03-30 15:19:15 · 6247 阅读 · 0 评论 -
[leetcode] 277. Find the Celebrity 解题报告
题目链接:https://leetcode.com/problems/find-the-celebrity/Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a cele原创 2016-03-19 04:09:27 · 3892 阅读 · 0 评论 -
[leetcode] 88. Merge Sorted Array 解题报告
题目链接:https://leetcode.com/problems/merge-sorted-array/Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough原创 2015-12-27 14:05:15 · 447 阅读 · 0 评论 -
[leetcode] 7. Reverse Integer 解题报告
题目链接:https://leetcode.com/problems/reverse-integer/Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321思路:注意溢出情况处理class Solution {public: in原创 2016-02-13 16:54:59 · 437 阅读 · 0 评论 -
[leetcode] 273. Integer to English Words 解题报告
题目链接:https://leetcode.com/problems/integer-to-english-words/Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,原创 2016-02-25 03:49:10 · 1156 阅读 · 0 评论