leetcode
轻春
Talk is cheap, show me the code.
展开
-
LeetCode 55. Jump Game
55. Jump Game一、问题描述 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 maximum jump length at that p原创 2017-06-05 20:20:39 · 211 阅读 · 0 评论 -
LeetCode 442. Find All Duplicates in an Array
**442. Find All Duplicates in an Array** Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.原创 2017-05-22 21:53:11 · 229 阅读 · 0 评论 -
LeetCode 402. Remove K Digits
402. Remove K Digits一、问题描述 Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of原创 2017-06-19 14:35:10 · 624 阅读 · 0 评论 -
LeetCode 621. Task Scheduler
621. Task Scheduler一、问题描述 Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without origin原创 2017-06-19 16:34:44 · 3690 阅读 · 0 评论 -
LeetCode 435. Non-overlapping Intervals
435. Non-overlapping Intervals一、问题描述 Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note: You原创 2017-06-19 20:38:15 · 552 阅读 · 0 评论 -
LeetCode 406. Queue Reconstruction by Height
406. Queue Reconstruction by Height一、问题描述 Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and原创 2017-06-19 20:38:30 · 474 阅读 · 0 评论 -
LeetCode 502. IPO
502. IPO一、问题描述 Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before th原创 2017-06-21 21:46:35 · 700 阅读 · 0 评论 -
LeetCode 330. Patching Array
330. Patching Array一、问题描述 Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n]inclusive can be formed by the sum of some e原创 2017-06-21 23:56:21 · 613 阅读 · 0 评论 -
LeetCode 108. Convert Sorted Array to Binary Search Tree
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.二、输入输出三、解题思路Binary Search Tree 二叉搜索树定义为:是指一颗空树原创 2017-07-11 17:44:33 · 532 阅读 · 0 评论 -
LeetCode 448. Find All Numbers Disappeared in an Array
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.原创 2017-05-22 21:56:16 · 172 阅读 · 0 评论 -
LeetCode 27. Remove Element
27. Remove Element Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in pla原创 2017-05-22 20:40:28 · 162 阅读 · 0 评论 -
LeetCode 134. Gas Station
134. Gas Station一、问题描述 There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to t原创 2017-06-05 21:26:39 · 220 阅读 · 0 评论 -
LeetCode 392. Is Subsequence
392. Is Subsequence一、问题描述 Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very l原创 2017-06-06 12:19:59 · 229 阅读 · 0 评论 -
LeetCode 66.Plus One
66.Plus One一、问题描述 Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number原创 2017-05-22 15:03:52 · 244 阅读 · 0 评论 -
LeetCode 219.Contains Duplicate II
219.Contains Duplicate II Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j]*and the **absolute differ原创 2017-05-22 16:26:04 · 166 阅读 · 0 评论 -
LeetCode 566.Reshape the Matrix
566.Reshape the Matrix In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.原创 2017-05-22 16:27:09 · 301 阅读 · 0 评论 -
LeetCode 13.Roman to Integer
13.Roman to Integer Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.解题思路罗马数字大部分都是在加,有个特殊情况是减当左边的数字小于右边的数字,且为IXC之一的时候就要减去这个数字原创 2017-05-22 16:28:10 · 279 阅读 · 0 评论 -
LeetCode 476. Number Complement
476. Number Complement Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.原创 2017-05-22 16:29:01 · 432 阅读 · 0 评论 -
LeetCode 532. K-diff Pairs in an Array
532. K-diff Pairs in an Array Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i,原创 2017-05-22 20:39:48 · 262 阅读 · 0 评论 -
LeetCode 111. Minimum Depth of Binary Tree
111. Minimum Depth of Binary Tree一、问题描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf原创 2017-07-11 17:44:56 · 474 阅读 · 0 评论 -
LeetCode 61. Rotate List
61. Rotate List一、问题描述 Given a list, rotate the list to the right by k places, where k is non-negative.二、输入输出For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.三、解题思路这道题的原创 2017-06-22 17:33:42 · 677 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers
2. Add Two Numbers一、问题描述 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add th原创 2017-06-23 16:42:38 · 634 阅读 · 0 评论 -
LeetCode 67. Add Binary
67. Add Binary一、问题描述 Given two binary strings, return their sum (also a binary string).二、输入输出For example, a = "11" b = "1" Return "100".三、解题思路从后向前遍历这道题看着不难,有几个点需要注意。首先最好不要转换成int或者二进制的数来进行计算,再转换回原创 2017-07-06 19:54:02 · 697 阅读 · 0 评论 -
LeetCode 69. Sqrt(x)
69. Sqrt(x)一、问题描述 Implement int sqrt(int x). Compute and return the square root of x.二、输入输出三、解题思路二分法直接写二分法超时了,不知道为什么 int Sqrt(int x, int low, int high) { int mid; while原创 2017-07-06 20:35:28 · 666 阅读 · 0 评论 -
LeetCode 101. Symmetric Tree
101. Symmetric Tree一、问题描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).二、输入输出For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \原创 2017-07-10 13:17:19 · 511 阅读 · 0 评论 -
LeetCode 10. Same Tree
10. Same Tree一、问题描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the sa原创 2017-07-10 13:17:35 · 442 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree
104. 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 down to the farthest leaf原创 2017-07-10 13:57:38 · 550 阅读 · 0 评论 -
LeetCode 107. Binary Tree Level Order Traversal II
107. Binary Tree Level Order Traversal II一、问题描述 Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).二、输入输原创 2017-07-10 13:57:54 · 581 阅读 · 0 评论 -
二叉树之理解记忆并背诵,了解一下?
内容主要包含: 1. 二叉树中DFS三种搜索的模板程序 (递归+非递归) 2. 二叉树BFS非递归版本 3. 二叉树常见到必背的考题 不管你是刷题学习,还是准备面试,二叉树下面的这几个程序都是 理解记忆并背诵!理解记忆并背诵!理解记忆并背诵!重要的事情说三遍真的太常用了,小哥哥小姐姐一定要掌握哦~BFS递归版本void bfs(TreeNode...原创 2018-04-09 22:36:53 · 672 阅读 · 0 评论 -
LeetCode 58. Length of Last Word
58. 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. If the last word does not exis原创 2017-07-05 19:13:47 · 678 阅读 · 0 评论 -
LeetCode 28. Implement strStr()
28. Implement strStr()一、问题描述 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.二、输入输出三、解题思路转换成:判断两个字符串prefix是否相同单独处理原创 2017-07-05 17:37:52 · 633 阅读 · 0 评论 -
LeetCode 3. Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters一、问题描述 Given a string, find the length of the longest substring without repeating characters.二、输入输出Examples:Given "abcabcbb", the answer is "abc", wh原创 2017-07-03 17:30:22 · 449 阅读 · 0 评论 -
LeetCode 4. Median of Two Arrays
4. Median of Two Arrays一、问题描述 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log原创 2017-07-04 00:42:59 · 599 阅读 · 1 评论 -
LeetCode 7. Reverse Integer
7. Reverse Integer一、问题描述 Reverse digits of an integer. **Have you thought about this?**Here are some good questions to ask before coding. Bonus points for you if you have already thought through原创 2017-07-04 15:52:10 · 416 阅读 · 0 评论 -
LeetCode 9. Palindrome Number
9. Palindrome Number一、问题描述 Determine whether an integer is a palindrome. Do this without extra space. **Some hints:**Could negative integers be palindromes? (ie, -1)If you are thinking of conver原创 2017-07-04 16:34:51 · 384 阅读 · 0 评论 -
LeetCode 20. Valid Parentheses
20. Valid Parentheses一、问题描述 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "原创 2017-07-05 16:03:14 · 521 阅读 · 0 评论 -
LeetCode 14. Longest Common Prefix
14. Longest Common Prefix一、问题描述 Write a function to find the longest common prefix string amongst an array of strings.二、输入输出三、解题思路二路归并解题思路:如果给你两个字符串,让你找出最大的common prefix 你一定有办法(对吧?)简单说就是取第一个字符串的子串,原创 2017-07-05 16:03:33 · 526 阅读 · 0 评论 -
LeetCode 500. Keyboard Row
500. Keyboard Row一、问题描述 Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below. 二、输入输出Example 1:Input:原创 2017-06-26 14:59:34 · 503 阅读 · 0 评论 -
LeetCode 617. Merge Two Binary Trees
617. Merge Two Binary Trees一、问题描述 Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You ne原创 2017-06-26 15:21:49 · 583 阅读 · 0 评论 -
N皇后问题
N皇后问题-I问题描述 n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击。 给定一个整数n,返回所有不同的n皇后问题的解决方案。 每个解决方案包含一个明确的n皇后放置布局,其中“Q”和“.”分别表示一个女王和一个空位置。样例: 对于4皇后问题存在两种解决的方案:[ [".Q..", // Solution 1 ".....原创 2018-05-04 00:49:40 · 245 阅读 · 0 评论