
LeetCode
文章平均质量分 72
_xiaoyuer
世界一定有光
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode - 474 - Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the ot原创 2017-04-17 21:47:36 · 237 阅读 · 0 评论 -
LeetCode - 523 - Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up t原创 2017-04-18 22:31:14 · 197 阅读 · 0 评论 -
LeetCode - 516 - Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palind原创 2017-04-18 23:12:41 · 204 阅读 · 0 评论 -
LeetCode - 542 - 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00原创 2017-04-17 20:23:17 · 260 阅读 · 0 评论 -
LeetCode - 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.Exam原创 2017-04-19 14:00:55 · 263 阅读 · 0 评论 -
LeetCode - 436 - Find Right Interval
Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on原创 2017-04-16 16:15:03 · 223 阅读 · 0 评论 -
LeetCode - 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 may assume the interval's end point is alw原创 2017-04-16 16:31:58 · 228 阅读 · 0 评论 -
LeetCode - 56 - Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].Subscribe to see which companies asked this qu原创 2017-04-16 16:41:49 · 176 阅读 · 0 评论 -
LeetCode - 485 - Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv原创 2017-04-25 21:34:29 · 289 阅读 · 0 评论 -
LeetCode - 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, j), where i and j are both numbers原创 2017-04-25 22:57:57 · 265 阅读 · 0 评论 -
LeetCode - 606 - Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". And yo原创 2017-06-18 21:14:51 · 456 阅读 · 0 评论 -
LeetCode - 572 - Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this no原创 2017-07-11 09:40:21 · 266 阅读 · 0 评论 -
LeetCode - 563 - Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtre原创 2017-07-11 10:09:36 · 217 阅读 · 0 评论 -
LeetCode - 225 - Implement Stack using Queues(队列实现栈)
苦苦思索怎么用两个队列实现栈,越想越复杂,越想越懵逼,然后发现解决区的大神一个队列就搞定了【幽灵幽灵飘】可能是模拟队列是用两个栈实现的,然后导致潜意识觉得实现栈也需要用两个队列吧。思维固化orzzzzzclass MyStack {public: queue q; /** Push element x onto stack. */ void push(原创 2017-07-01 11:04:12 · 317 阅读 · 0 评论 -
LeetCode - 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.原创 2017-07-11 11:13:54 · 205 阅读 · 0 评论 -
LeetCode - 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.Find all the elements that appear twice in this array.Could you do it without ex原创 2017-07-11 11:05:03 · 181 阅读 · 0 评论 -
LeetCode - 53 - Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] ha原创 2017-07-11 11:32:56 · 182 阅读 · 0 评论 -
LeetCode - 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 the two numbers and return i原创 2017-06-21 20:10:16 · 202 阅读 · 0 评论 -
LettCode - 5 - Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.原创 2017-06-22 20:07:03 · 226 阅读 · 0 评论 -
LeetCode - 16 - 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2017-07-12 09:33:38 · 204 阅读 · 0 评论 -
LeetCode - 18 - 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution s原创 2017-07-12 09:33:52 · 159 阅读 · 0 评论 -
LeetCode - 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 l原创 2017-07-12 09:34:07 · 217 阅读 · 0 评论 -
LeetCode - 94/144/145 - 二叉树遍历
嗯,发现非递归方法是有必要掌握的,递归思路比较好想,非递归,其实思路是一样的,就是为啥自己老是绕不过去。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int原创 2017-07-01 10:24:25 · 249 阅读 · 0 评论 -
LeetCode - 15 - 3Sum(内有two sum)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain原创 2017-07-12 09:33:23 · 190 阅读 · 0 评论 -
LeetCode - 137 - Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could yo原创 2017-07-13 10:09:00 · 199 阅读 · 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原创 2017-07-13 10:12:45 · 225 阅读 · 0 评论 -
LeetCode - 389 - Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was原创 2017-07-13 10:21:25 · 236 阅读 · 0 评论 -
LeetCode - 191/190/338 - 二进制有多少个1
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x,原创 2017-07-13 10:16:27 · 397 阅读 · 0 评论 -
LeetCode - 461/477 - Hamming Distance
461 - Hamming DistanceThe Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming原创 2017-07-13 10:19:08 · 236 阅读 · 0 评论 -
LeetCode - 169/229 - Majority Element
169. Majority ElementGiven 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-em原创 2017-07-14 09:24:11 · 223 阅读 · 0 评论 -
LeetCode - 26/80/27/283 - Remove/Move Element from Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2017-07-14 09:25:06 · 214 阅读 · 0 评论 -
LeetCode - 21/23/88 - Merge Sorted Lists/Array
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.唔,这题的思路,咋写啊。。。就是,比较两个链表当前值的大小,取值小的那个。时间复杂度O(n),空间复杂度O原创 2017-07-14 09:27:12 · 211 阅读 · 0 评论 -
LeetCode - 263/264/313 - Ugly Number
263. Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,6, 8are ugly while14...原创 2017-07-14 09:58:40 · 215 阅读 · 0 评论 -
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原创 2017-07-12 09:34:21 · 357 阅读 · 3 评论 -
LeetCode - 202 - Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares原创 2017-07-15 14:24:52 · 251 阅读 · 0 评论 -
LeetCode - 141/142 - Linked List Cycle
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断链表是否成环。设定两个指针,一个每次走一步,一个每次走两步,如果都不为空且相等了,就说明成环原创 2017-07-15 14:25:09 · 195 阅读 · 0 评论 -
LeetCode - 287 - Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,原创 2017-07-15 14:25:30 · 267 阅读 · 0 评论 -
LeetCode - 83/82/203/19 - Remove Elements from Linked List
83 - Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3原创 2017-07-14 09:25:59 · 286 阅读 · 0 评论 -
LeetCode - 70 - Climbing Stairs
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 climb to the top?Note: Given n will be a posi原创 2017-07-15 15:00:59 · 194 阅读 · 0 评论 -
LeetCode - 62/63/64 - Unique Paths/Minimum Path Sum
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 point in time. The robot is trying to reach the bo原创 2017-07-16 09:51:17 · 820 阅读 · 0 评论