
LeetCode
文章平均质量分 66
xclfafa
这个作者很懒,什么都没留下…
展开
-
leetcode 754. Reach a Number
题目:You are standing at position 0 on an infinite number line. There is a goal at position target.On each move, you can either go left or right. During the n-th move (starting from 1), you take n steps...原创 2018-04-14 11:04:10 · 298 阅读 · 0 评论 -
leetcode 307. Range Sum Query - Mutable
题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.原创 2017-11-02 11:02:54 · 170 阅读 · 0 评论 -
leetcode 456. 132 Pattern
题目:Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i j k and ai < ak j. Design an algorithm that takes a list of n numbers as input原创 2017-10-25 12:00:07 · 179 阅读 · 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.void f(vector &r原创 2017-10-24 16:43:38 · 183 阅读 · 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 poi原创 2017-10-24 10:37:05 · 204 阅读 · 0 评论 -
leetcode 204. Count Primes
题目:Description:Count the number of prime numbers less than a non-negative number, n.思路:暴力求解是一种,还有就是筛选法,创建一个n的数组,初始化为true,遍历开始,就是当i是质(素)数的时候,i的所有的倍数必然是合数。如果i已经被判断不是质数了,那么再找到i后面的质数来把这个质数的倍原创 2017-10-23 18:42:55 · 139 阅读 · 0 评论 -
leetcode 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原创 2017-10-23 18:21:20 · 135 阅读 · 0 评论 -
leetcode House Robber
题目:198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each原创 2017-10-29 21:34:01 · 198 阅读 · 0 评论 -
Leetcode 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 elements in the原创 2017-10-21 12:00:44 · 144 阅读 · 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 n原创 2017-11-06 20:39:12 · 184 阅读 · 0 评论 -
leetcode 686. Repeated String Match
题目:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.For example, with A = "abcd" and B = "cda原创 2017-10-29 11:27:19 · 394 阅读 · 0 评论 -
leetcode 229. Majority Element II
题目:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.思路:http://www.cnblogs.com/grandyang/p/4606原创 2017-11-02 15:09:11 · 178 阅读 · 0 评论 -
leetcode 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 position.De原创 2017-10-25 22:21:42 · 155 阅读 · 0 评论 -
leetcode 648. Replace Words
题目:In English, we have a concept called root, which can be followed by some other words to form another longer word - let's call this word successor. For example, the root an, followed by othe原创 2017-11-03 20:46:06 · 215 阅读 · 0 评论 -
Leetcode 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 &l...原创 2018-04-12 17:01:40 · 190 阅读 · 0 评论 -
Leetcode 329. Longest Increasing Path in a Matrix
题目:Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside ...原创 2018-04-05 16:57:27 · 228 阅读 · 0 评论 -
leetcode 780. Reaching Points
题目:A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of mov...原创 2018-04-16 12:16:12 · 283 阅读 · 0 评论 -
leetcode 647. Palindromic Substrings
题目:Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even th原创 2017-12-03 23:21:37 · 187 阅读 · 0 评论 -
leetcode 233. Number of Digit One
题目:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the原创 2017-12-02 23:04:59 · 181 阅读 · 0 评论 -
leetcode 214. Shortest Palindrome
题目:Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.原创 2017-12-02 17:58:06 · 214 阅读 · 0 评论 -
leetcode 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原创 2017-12-02 16:17:31 · 153 阅读 · 0 评论 -
leetcode 132. Palindrome Partitioning II
题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",R原创 2017-12-02 14:55:58 · 145 阅读 · 0 评论 -
leetcode 539. Minimum Time Difference
题目:Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list.Example 1:Input: ["23:59","00:00"]Outp原创 2017-12-01 13:51:47 · 185 阅读 · 0 评论 -
leetcode 416. Partition Equal Subset Sum
题目:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of原创 2017-11-06 15:06:37 · 189 阅读 · 0 评论 -
Leetcode 513. Find Bottom Left Tree Value
题目:Given a binary tree, find the leftmost value in the last row of the tree.void f(TreeNode* root,int cur,vector>& re){ if(root !=NULL){ if(cur < re.size()){ re[cur].push原创 2017-10-20 16:04:55 · 138 阅读 · 0 评论 -
Leetcode 390. Elimination Game
raw blog:http://blog.youkuaiyun.com/corpsepiges/article/details/52573281 题目:There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other numbe翻译 2017-10-10 16:56:49 · 271 阅读 · 0 评论 -
leetcode 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 on原创 2017-10-19 12:03:12 · 147 阅读 · 0 评论 -
LeetCode 517. Super Washing Machines
题目:You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.For each move, you could choose any m (1 ≤ m ≤ n) washing machines, and pass one原创 2017-09-03 22:57:30 · 230 阅读 · 0 评论 -
Leetcode 174. Dungeon Game
题目:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was init原创 2017-06-14 19:37:48 · 267 阅读 · 0 评论 -
Leetcode 152. Maximum Product Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the原创 2017-06-13 11:04:44 · 458 阅读 · 0 评论 -
Leetcode 142. Linked List Cycle II
题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.思路:快慢指针的使用。首先,first为快指针,每次只走一步;second为慢指针,每次走两步;快慢指针同时开始遍历,当快慢指针相等时,说明有环。并且,假设链表开始到环起点长为 s,环长为 l;当se原创 2017-06-11 21:45:15 · 234 阅读 · 0 评论 -
Leetcode 143. Reorder List
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reord原创 2017-06-11 21:34:57 · 162 阅读 · 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.思路:对于前n为的数如果已经统原创 2017-06-22 15:24:34 · 147 阅读 · 0 评论 -
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.原创 2017-06-21 08:44:43 · 246 阅读 · 0 评论 -
Leetcode 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 travel from statio原创 2017-06-08 21:01:34 · 185 阅读 · 0 评论 -
Leetcode 600. Non-negative Integers without Consecutive Ones
题目:Given a positive integer n, find the number of non-negative integers less than or equal to n, whose binary representations do NOT contain consecutive ones。思路:对于每个数的二进制表示,假设这个数有n位。令f(n) 表示从右到左第n原创 2017-06-17 14:23:44 · 874 阅读 · 0 评论 -
LeetCode 75. 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 red, white and blue.Here, we will use the in原创 2017-05-15 18:58:57 · 306 阅读 · 0 评论 -
Leetcode 221. Maximal Square
题目:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11原创 2017-09-13 09:45:47 · 172 阅读 · 0 评论 -
LeetCode 394. Decode String
题目:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note原创 2017-08-23 17:45:50 · 202 阅读 · 0 评论 -
LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.class Solution {public: TreeNode* f(v原创 2017-08-23 22:50:05 · 164 阅读 · 0 评论