![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 73
bupt8846
这个作者很懒,什么都没留下…
展开
-
leetcode - Container With Most Water
题目:Container With Most WaterGiven n non-negative integers a1, a2, ...,an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints转载 2015-06-20 20:37:06 · 451 阅读 · 0 评论 -
leetcode - Lowest Common Ancestor of a Binary Tree
题目:Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of原创 2015-07-11 10:55:28 · 907 阅读 · 0 评论 -
leetcode - Decode Ways
题目:Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits,原创 2015-07-06 12:15:09 · 558 阅读 · 0 评论 -
leetcode - Sliding Window Maximum
题目:Sliding Window MaximumGiven an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the win原创 2015-07-18 11:49:33 · 959 阅读 · 0 评论 -
leetcode - 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,123 -> "One Hundred Twenty Three"12345 -> "Twelve Th原创 2015-09-05 01:17:08 · 524 阅读 · 0 评论 -
leetcode - Move Zeroes
题目:Move ZeroesGiven an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3原创 2015-09-19 15:44:15 · 449 阅读 · 0 评论 -
leetcode - Additive Number
题目:https://leetcode.com/problems/additive-number/class Solution {public: long long str2num(string str){ stringstream ss(str); long long n; ss >> n; return n; } string num2str(l原创 2016-02-13 23:12:11 · 414 阅读 · 0 评论 -
leetcode - Range Sum Query - Mutable
题目:https://leetcode.com/problems/range-sum-query-mutable/思路:使用数据结构线段树,在NumArray的构造函数中递归构造线段树。//线段树节点class Node{public: int Min, Max, sum;//Min, Max表示该节点的区间为[Min,Max] Node* left,原创 2016-02-15 00:38:49 · 337 阅读 · 0 评论 -
leetcode - Best Time to Buy and Sell Stock with Cooldown
题目:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/参考这里class Solution {public: int maxProfit(vector& prices) { if (prices.size() <= 1) return 0; if (原创 2016-02-15 17:38:30 · 401 阅读 · 0 评论 -
leetcode - Super Ugly Number
题目:https://leetcode.com/problems/super-ugly-number/参考这里。注意一定代码中heap一定要使用multiset!!!class Node{public: int index, prime, val; Node(int a, int b, int c) :index(a), prime(b), val(c){}转载 2016-02-15 21:02:39 · 405 阅读 · 0 评论 -
leetcode - Minimum Height Trees
题目:https://leetcode.com/problems/minimum-height-trees/参考这里class Node{public: int id; unordered_set next; Node(int a) :id(a){}};class Solution {public: vector findMinHeightTre转载 2016-02-15 22:49:44 · 430 阅读 · 0 评论 -
leetcode - Maximum Product of Word Lengths
题目:https://leetcode.com/problems/maximum-product-of-word-lengths/提示:使用位操作class Solution {public: int maxProduct(vector& words) { if(words.size() re原创 2016-02-15 23:47:48 · 515 阅读 · 0 评论 -
leetcode - Count of Smaller Numbers After Self
题目: https://leetcode.com/problems/count-of-smaller-numbers-after-self/思路: 使用线段树,参考这里。class Solution{ class Node//线段树节点 { public: int ll,rr,cnt; // 在范围[ll,rr]内的值有cnt个 Node转载 2016-03-03 15:06:11 · 636 阅读 · 0 评论 -
leetcode - Remove Invalid Parentheses
题目:https://leetcode.com/problems/remove-invalid-parentheses/思路:广度优先遍历。在返回最终结果res前,注意去重!class Solution{public: //参数kuohao代表此次递归里cur中左括号数量减去右括号数量的值,可见kuohao是非负整数 void removeInvalidParent原创 2016-03-03 16:59:24 · 637 阅读 · 0 评论 -
letcode - Dungeon Game
题目:Dungeon GameThe 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 knigh原创 2015-07-27 23:30:25 · 659 阅读 · 0 评论 -
leetcode - Search a 2D Matrix II
题目:Search a 2D Matrix IIWrite an efficient algorithm that searches for a value in anm x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending原创 2015-07-25 13:52:56 · 902 阅读 · 0 评论 -
leetcode - Longest Palindromic Substring
题目: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, and there exists one unique longest原创 2015-06-20 16:35:32 · 637 阅读 · 0 评论 -
leetcode - Merge k Sorted Lists
题目:Merge k Sorted ListsMergek sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 分析:用multiset作为小根堆,multiset的begin是value最小的结点。注意:原创 2015-06-21 09:45:02 · 767 阅读 · 0 评论 -
leetcode - Divide Two Integers
题目:Divide Two Integers Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 分析:1、设法在不溢出的前提下,把除数和被除数转化成正数进行计算。原创 2015-06-22 16:11:32 · 512 阅读 · 0 评论 -
leetcode - Next Permutation
题目:Next Permutation Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rea原创 2015-06-22 17:59:18 · 468 阅读 · 0 评论 -
leetcode - One Edit Distance
题目:One Edit DistanceGiven two strings S and T, determine if they are both oneedit distance apart.Hint:1. If | n – m | is greater than 1, we know immediately both are not one-editdistance a原创 2015-06-04 15:27:10 · 628 阅读 · 0 评论 -
【回文】leetcode - Shortest Palindrome
题目: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 perf原创 2015-06-05 11:01:33 · 794 阅读 · 0 评论 -
leetcode - Missing Ranges
题目:Missing RangesGiven a sorted integer array where the range of elements are [0, 99]inclusive, return its missing ranges.For example, given [0, 1, 3, 50, 75], return[“2”, “4->49”, “51->74”, “原创 2015-06-04 16:15:00 · 775 阅读 · 0 评论 -
leetcode - Count Complete Tree Nodes
题目:Count Complete Tree Nodes Given a complete binary tree, count the number of nodes.In a complete binary tree every level, except possibly the last, is completely filled, and all转载 2015-06-06 17:35:37 · 489 阅读 · 0 评论 -
leetcode- Permutations II
题目: Permutations II Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1原创 2015-06-29 14:52:24 · 689 阅读 · 0 评论 -
leetcode - Jump Game II
题目:Jump Game II 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原创 2015-06-29 00:00:08 · 575 阅读 · 0 评论 -
leetcode - Valid Number
题目:Valid NumberValidate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueclass Solution {public: bool is原创 2015-06-10 11:07:47 · 689 阅读 · 0 评论 -
leetcode - Regular Expression Matching
题目:Regular Expression Matching '.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The原创 2015-06-09 21:28:09 · 532 阅读 · 0 评论 -
leetcode - Convert Sorted List to Binary Search Tree
题目:Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked l转载 2015-07-09 23:51:30 · 470 阅读 · 0 评论 -
leetcode - Create Maximum Number
题目: https://leetcode.com/problems/create-maximum-number/思路:从nuns1中选[0, min(nums1.size(),k] 个数字,剩下的从nuns2选,选出来后按照规则组合成一个数字,最大的为答案。注意边界条件。class Solution{public: vector maxNumber(v原创 2016-03-04 14:41:14 · 740 阅读 · 2 评论