![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 71
RicardoLei
这个作者很懒,什么都没留下…
展开
-
LeetCode 199.Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1原创 2016-10-16 11:19:15 · 383 阅读 · 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.原创 2017-04-24 20:12:06 · 290 阅读 · 0 评论 -
LeetCode 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: ["Hello", "Alaska", "Da原创 2017-05-15 22:35:35 · 268 阅读 · 0 评论 -
LeetCode 541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of th原创 2017-06-05 21:00:35 · 408 阅读 · 0 评论 -
LeetCode 9. Palindrome Number
LeetCode 9. Palindrome Number本题要求判断一个整型变量x是否回文数。具体需要考虑一下几点:负数是否为回文数如果转置的话,是否会出现越界的情况如果要将整型转化为字符串的话,还需要考虑空格的情况题目给出的框架如下:class Solution {public: bool isPalindrome(int x) { }};解题思路方法一:用stack来原创 2017-06-28 17:39:35 · 320 阅读 · 0 评论 -
LeetCode 11. Container With Most Water
LeetCode 11. Container With Most Water题目要求:给出n个非负的整数a1,a2,… an。分别得到n个点(i,ai)。每个点(i,ai)与x轴上对应的点(i,0)组成一条垂直于x轴的线段。求任意两条直线以及x轴形成的最大容器体积。 容器的体积为对应两条线段之间的距离乘以较小的线段长度。解题思路一开始用的是最蠢的方法,即使用双重循环,对任意两条边进行比较,然后华丽原创 2017-06-28 21:15:09 · 364 阅读 · 0 评论 -
LeetCode 7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function s原创 2017-06-12 21:43:34 · 231 阅读 · 0 评论 -
LeetCode 13. Roman to Integer
Roman to Integer题目要求:给出一个罗马数字,要求转化为整型数字。 题目给出的框架如下:class Solution {public: int romanToInt(string s) { }};先验知识:下面为罗马数字与阿拉伯数字的对照表: 罗马数字 阿拉伯数字 I 1 V 5 X 10 L 50 C 100 D原创 2017-07-03 23:17:52 · 223 阅读 · 0 评论 -
LeetCode 14. Longest Common Prefix
LeetCode 14. Longest Common Prefix题目要求:找出一组字符串中的最长公共前缀。 题目给出的框架如下:class Solution {public: string longestCommonPrefix(vector<string>& strs) { }};解题思路: 采用的是很直接的方法,如果为输入字符串个数为0,则直接返回空字符串,如果只有一个原创 2017-07-03 23:49:15 · 198 阅读 · 0 评论 -
LeetCode 15. 3Sum
LeetCode 15. 3Sum题目要求:给出一个整型数组S。找出里面所有的a,b,c使得a+b+c=0,要求每组数据不能完全相同。 题目给出的框架如下:class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { }};解题思路3Sum与2Sum的思路是一致的,都是先进行排序,然后采用首尾两原创 2017-07-05 15:35:07 · 286 阅读 · 0 评论 -
LeetCode 113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2017-05-01 22:13:52 · 312 阅读 · 0 评论 -
LeetCode 44. Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2017-04-17 21:15:44 · 252 阅读 · 0 评论 -
LeetCode 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2016-10-15 17:14:22 · 231 阅读 · 0 评论 -
LeetCode 116 Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2016-10-16 13:01:26 · 341 阅读 · 0 评论 -
LeetCode 88. Merge Sorted Array
Merge Sorted Array的意思是将两个有序的数组nums1和nums2合并成为一个有序的数组nums1。原题如下:class Solution {public: void merge(vector& nums1, int m, vector& nums2, int n) { }};思路如下:对nums1的元素从尾部开始进行移动操原创 2016-09-26 23:25:24 · 318 阅读 · 0 评论 -
LeetCode 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.原创 2017-03-05 21:12:31 · 356 阅读 · 0 评论 -
LeetCode 240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in原创 2017-03-12 21:36:40 · 318 阅读 · 0 评论 -
LeetCode 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2017-04-10 19:14:08 · 277 阅读 · 0 评论 -
LeetCode 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", which the length is 3.Given "bbbbb", the answer is "原创 2017-03-26 22:20:56 · 208 阅读 · 0 评论 -
LeetCode 208. Implement Trie (Prefix Tree)
如题所示,要求实现字典树的插入,查找单词,和查找前缀的方法。Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.Subscribe to see原创 2017-03-19 23:53:18 · 239 阅读 · 0 评论 -
LeetCode 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-04-03 21:44:43 · 224 阅读 · 0 评论 -
LeetCode 16. 3Sum Closest
LeetCode 16. 3Sum Closest题目要求:给出一个整型数组nums和一个整数target,要求从nums中找出3个整数a,b,c使得它们的和最接近target。 题目给出的框架如下所示:class Solution {public: int threeSumClosest(vector<int>& nums, int target) { }};解题思路这道题和之原创 2017-07-05 16:53:38 · 308 阅读 · 0 评论