leetcode
LUCASYAN个
这个作者很懒,什么都没留下…
展开
-
417. Pacific Atlantic Water Flow
4原创 2017-09-06 14:23:10 · 135 阅读 · 0 评论 -
567. Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.Ex原创 2017-09-16 09:01:38 · 297 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi原创 2017-09-16 09:02:04 · 219 阅读 · 0 评论 -
636. Exclusive Time of Functions
Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find the exclusive time of these functions.Each function has a unique id, start from 0 to n-1. A fun原创 2017-09-16 09:02:56 · 305 阅读 · 0 评论 -
301. Remove Invalid Parentheses
6原创 2017-09-06 14:23:33 · 207 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
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原创 2017-09-16 08:59:15 · 204 阅读 · 0 评论 -
双指针+哈希表类题目Longest Substring Without Repeating Charac Longest Substring Without Repeating Characters
76. Minimum Window SubstringGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T =原创 2017-09-04 22:59:07 · 244 阅读 · 0 评论 -
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 the array原创 2017-09-16 08:59:39 · 237 阅读 · 0 评论 -
368. Largest Divisible Subset
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 that k is原创 2017-09-16 09:03:20 · 220 阅读 · 0 评论 -
208. Implement Trie (Prefix Tree)
实现一个字典树要求:实现插入一个单词,查找一个单词,是否有某个前缀思路:不需要查找前缀单词的数目,也不需要删除一个单词。因此实现起来比较简单。字典树节点中只需要设置一个isEnd变量标记单词结束即可。class TrieNode{ public: //因为这个题目不需要统计个数,不需要删除单词,所以,只设置结尾标志 TrieNode* next[26];原创 2017-09-16 09:03:46 · 225 阅读 · 0 评论 -
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 integers原创 2017-09-16 09:01:10 · 223 阅读 · 0 评论 -
524. Longest Word in Dictionary through Deleting
Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, retur原创 2017-09-16 09:00:42 · 178 阅读 · 0 评论 -
312 Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get num原创 2017-09-16 08:58:35 · 159 阅读 · 0 评论 -
207. Course Schedule
3原创 2017-09-06 14:22:59 · 134 阅读 · 0 评论 -
310. Minimum Height Trees
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 long (length ~= 500,000) strin原创 2017-09-05 00:06:28 · 165 阅读 · 0 评论 -
210. Course Schedule II
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordin原创 2017-09-05 00:06:08 · 151 阅读 · 0 评论 -
529. Minesweeper 扫雷游戏 DFS BFS
Let's play the minesweeper game (Wikipedia, online game)!You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an unrevealed empty square,原创 2017-09-06 14:23:56 · 530 阅读 · 0 评论 -
leetcode 栈 全部题目
232 Implement Queue using Stacks36.5% Easy225 Implement Stack using Queues32.7% Easy155 Min Stack 28.4% Easy20 Valid Parentheses33.3% Easy496 Next Greater Element I56.9% Easy173 Bi原创 2017-07-23 22:22:18 · 422 阅读 · 0 评论 -
42. Trapping Rain Water 及类似题目 407. Trapping Rain Water II 11. Container With Most Water
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dict原创 2017-09-05 00:09:45 · 250 阅读 · 0 评论 -
646. Maximum Length of Pair Chain 类似与最长子序列但是有简单做法 贪心方法
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain原创 2017-09-07 22:46:25 · 239 阅读 · 0 评论 -
334. Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar原创 2017-09-07 22:59:20 · 203 阅读 · 0 评论 -
669. Trim a Binary Search Tree
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly twoor zero sub-node. If the node has two sub-nodes, then this node's v原创 2017-09-24 20:05:09 · 280 阅读 · 0 评论 -
10. Regular Expression Matching 字符串匹配 左程云
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st原创 2017-09-17 19:39:23 · 491 阅读 · 1 评论 -
leetcode 链表所有题目
简单题目141 判断一个链表是否有环 使用快慢指针class Solution { public: bool hasCycle(ListNode *head) { ListNode* pFast=head; ListNode* pSlow=head; if(head==NULL) return fals原创 2017-07-23 15:36:19 · 405 阅读 · 0 评论 -
蓄水池算法
基本概念参考程序员面试指南 这种方法关键是理解思想,实际的代码非常简单。leetcode变形题398. Random Pick IndexGiven an array of integers with possible duplicates, randomly output the index of a given target number. You can assume t原创 2017-09-26 12:50:57 · 1366 阅读 · 0 评论 -
动态规划之极小化极大值问题 375. Guess Number Higher or Lower II
这类题目思想是两层极值问题。比如要求求出一个极大值,而这个极大值的选择是在众多的极小值中选择的。1、375. Guess Number Higher or Lower II在1~n中给定一个数,要求猜测这个数是多少,最后猜出这个数的代价是之前猜的数的和。在374类似问题中,是求解最少的猜测次数,使用二分法的思想。这个题目如果受这种思想的限制,就想不到一个合适的解法。回归到最一般原创 2017-09-20 17:26:28 · 1291 阅读 · 1 评论 -
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原创 2017-09-12 21:17:32 · 128 阅读 · 0 评论 -
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,55原创 2017-09-12 21:33:22 · 311 阅读 · 0 评论 -
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 long (length ~= 500,000) strin原创 2017-09-12 21:58:08 · 145 阅读 · 0 评论 -
494. Target Sum
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find out原创 2017-09-12 23:34:56 · 147 阅读 · 0 评论 -
150. Evaluate Reverse Polish Notation 逆波兰表达式
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+原创 2017-09-12 23:37:42 · 167 阅读 · 0 评论 -
467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we have原创 2017-09-22 09:58:08 · 278 阅读 · 0 评论 -
673. Number of Longest Increasing Subsequence 最长递增子序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3, 4, 7]原创 2017-09-22 10:55:35 · 1671 阅读 · 0 评论 -
403. Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given a list of s原创 2017-09-22 15:11:40 · 274 阅读 · 0 评论 -
667. Beautiful Arrangement II 找规律
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3,原创 2017-09-12 19:56:58 · 202 阅读 · 0 评论 -
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原创 2017-09-12 19:24:38 · 159 阅读 · 0 评论 -
594. Longest Harmonious Subsequence
We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of its longest h原创 2017-09-12 16:54:11 · 163 阅读 · 0 评论 -
分金子(360公司2017春招真题) 纸牌博弈问题 程序员代码面试指南
A、B两伙马贼意外地在一片沙漠中发现了一处金矿,双方都想独占金矿,但各自的实力都不足以吞下对方,经过谈判后,双方同意用一个公平的方式来处理这片金矿。处理的规则如下:他们把整个金矿分成n段,由A、B开始轮流从最左端或最右端占据一段,直到分完为止。 马贼A想提前知道他们能分到多少金子,因此请你帮忙计算他们最后各自拥有多少金子?(两伙马贼均会采取对己方有利的策略)输入原创 2017-09-18 20:00:56 · 918 阅读 · 0 评论 -
并查集 leetcode 编程题
先看先人的总结:[置顶] 并查集详解 (转)傻子都能看懂的并查集入门一、并查集简单总结1、数据parent 集合代表,rank集合层级,data 元素的数值2、三个操作初始化:将所有元素的集合代表设置成自己,rank层级设置成0,查找:查找一个元素的集合代表,原理是指针循环操作合并集合:将两个集合的集合代表设置成一个。一般根据rank原创 2017-09-26 20:17:31 · 2238 阅读 · 1 评论 -
82. Remove Duplicates from Sorted List II 删除排序链表中的重复数,重复的数全部删除
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->原创 2017-09-27 10:55:31 · 342 阅读 · 0 评论