![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 66
萝卜头-LEE
ACMer新手上路
展开
-
leetcode: 11. Container With Most Water
题意:输入n个数,每个数的值a[i]为该数的高(a[i] >= 0),其位置为该数的输入顺序(间隔为1),要求从这堆输入的数中找到两个高,使得这两个高之间的容器能装最多的水,注意:容器不能倾斜。解题思路:从离得最远的两个数入手,最远的两数拥有最大的宽度,然后当前的高为头尾两数的最小值,用宽高求出当前水容量ans。接着先从左往右寻找第一个比当前高要高的左下标i,再从右往左找比当前原创 2017-02-26 19:02:04 · 158 阅读 · 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 cov原创 2017-03-13 16:50:20 · 142 阅读 · 0 评论 -
leetcode:227. Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should trunca原创 2017-04-09 18:32:24 · 230 阅读 · 0 评论 -
87. Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”: great / \ gr eat原创 2017-04-09 19:57:58 · 138 阅读 · 0 评论 -
28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题意&解题思路如题,直接用KMP算法解决,代码如下:class Solution {public: int strStr(string hays原创 2017-04-09 20:43:38 · 147 阅读 · 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.Example: For num = 5 you sh原创 2017-04-19 20:37:02 · 265 阅读 · 0 评论 -
leetcode:413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:原创 2017-04-19 21:26:53 · 186 阅读 · 0 评论 -
leetcode:507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfect n原创 2017-04-16 23:18:38 · 342 阅读 · 0 评论 -
leetcode: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, return 1原创 2017-05-04 10:37:25 · 167 阅读 · 0 评论 -
leetcode: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) string, an原创 2017-05-17 10:32:35 · 187 阅读 · 0 评论 -
leetcode: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 how many w原创 2017-05-17 10:50:57 · 225 阅读 · 0 评论 -
leetcode:468. Validate IP Address
Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither.IPv4 addresses are canonically represented in dot-decimal notation, which consists of four deci原创 2017-03-13 14:43:43 · 602 阅读 · 0 评论 -
leetcode:115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2017-03-21 17:35:16 · 167 阅读 · 0 评论 -
leetcode:332. Reconstruct Itinerary
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus原创 2017-03-21 16:07:34 · 169 阅读 · 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 14:33:50 · 233 阅读 · 0 评论 -
leetcode: 2. Add Two Numbers
题意:将两个逆向链表表示的数加起来返回。解题思路:从低位到高位逐步把两个链表的数加起来赋给需要返回的链表,注意进位,每一步创建一个节点。当链表长度不一时,短的输入链表加完后再单独加上长的输入链表。/** * Definition for singly-linked list. * struct ListNode { * int val; * List原创 2017-02-26 18:29:41 · 202 阅读 · 0 评论 -
leetCode:493. Reverse Pairs
Given an array nums, we call (i, j) an important reverse pair if i and nums[i] > 2*nums[j].You need to return the number of important reverse pairs in the given array.解题思路:1.归并排序用原创 2017-03-05 22:20:37 · 440 阅读 · 0 评论 -
leetcode:125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2017-03-19 15:11:37 · 148 阅读 · 0 评论 -
leetcode:22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()原创 2017-03-19 15:43:27 · 155 阅读 · 0 评论 -
leetcode:459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli原创 2017-03-19 16:17:12 · 180 阅读 · 0 评论 -
leetcode:49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note: Al原创 2017-03-19 18:58:36 · 142 阅读 · 0 评论 -
leetcode:17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2017-03-19 17:35:07 · 147 阅读 · 0 评论 -
leetcode:67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题意&解题思路:字符串形式的二进制相加,暴力解决。注意处理多余的前导零。代码如下:class Solution {public: st原创 2017-03-19 19:54:42 · 159 阅读 · 0 评论 -
leetcode:72. Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2017-03-19 21:46:21 · 175 阅读 · 0 评论 -
leetcode:486. Predict the Winner
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a原创 2017-05-09 21:54:07 · 208 阅读 · 0 评论