![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 64
愤怒的菜鸟_
修行之路。。。
展开
-
leetcode-34. Search for a Range
class Solution {public: vector searchRange(vector& nums, int target) { int start = 0, end = nums.size() - 1; vector search; if (nums.empty()) { search.push_back(-1); search.push_back(-1)原创 2016-04-27 14:34:09 · 314 阅读 · 0 评论 -
leetcode:Valid Parentheses [20]
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2016-08-16 22:08:14 · 211 阅读 · 0 评论 -
leetcode:3Sum Closest [16]
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2016-08-11 22:08:49 · 152 阅读 · 0 评论 -
leetcode:3Sum [15]
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain原创 2016-08-11 22:07:06 · 148 阅读 · 0 评论 -
leetcode:Longest Common Prefix [14]
Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector& strs) { if (strs.size() == 0) return "";原创 2016-08-09 22:29:42 · 155 阅读 · 0 评论 -
leetcode:Roman to Integer [13]
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: int getVal(char a) { switch (a) { case 'I': return 1原创 2016-08-09 22:27:31 · 159 阅读 · 0 评论 -
leetcode:Integer to Roman [12]
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution { public: string intToRoman(int num) { string thousand[原创 2016-08-08 21:15:31 · 224 阅读 · 0 评论 -
leetcode:Letter Combinations of a Phone Number [17]
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原创 2016-08-15 10:13:40 · 151 阅读 · 0 评论 -
leetcode:4Sum [18]
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution原创 2016-08-15 10:14:46 · 187 阅读 · 0 评论 -
leetcode:Container With Most Water [11]
Given 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 of line i is at (i, ai) and (i,原创 2016-08-08 21:13:41 · 169 阅读 · 0 评论 -
leetcode:Regular Expression Matching [10]
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原创 2016-08-06 21:43:57 · 221 阅读 · 0 评论 -
leetcode:Remove Nth Node From End of List [19]
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2016-08-16 22:06:55 · 212 阅读 · 0 评论 -
leetcode[7] Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution {public: int reverse(int x) { if (x > 0) { int a = 0, b; while (x > 0)原创 2016-08-04 10:54:42 · 140 阅读 · 0 评论 -
leetcode-35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2016-04-27 14:40:40 · 211 阅读 · 0 评论 -
[LeetCode]1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums =原创 2016-04-17 23:03:57 · 195 阅读 · 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 answ原创 2016-04-23 14:32:42 · 190 阅读 · 0 评论 -
leetcode之Construct Binary Tree from Preorder and Inorder Traversal
题目:Given preorder and inorder traversal of a tree, construct the binary tree.根据前序序列和中序序列构建二叉树。思路:前序序列的第一数必然是根结点,中序序列中,在该根结点前面的数均为根结点的左子树结点,该结点后面的数均为根结点的右子树结点,根据这个规律不断递归即可构建完整的二叉树。代码/** * De原创 2016-06-27 09:00:38 · 204 阅读 · 0 评论 -
leetcode:Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri原创 2016-07-14 21:17:43 · 177 阅读 · 0 评论 -
leetcode:Course Schedule
题目:There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expr原创 2016-07-16 21:22:53 · 160 阅读 · 0 评论 -
leetcode:Word Search II
题目:Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are th原创 2016-07-18 21:45:56 · 175 阅读 · 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, and there exists one unique longest palindromic substring.clas原创 2016-08-04 10:51:38 · 181 阅读 · 0 评论 -
leetcode[6] ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2016-08-04 10:53:26 · 128 阅读 · 0 评论 -
leetcode:Palindrome Number [9]
Determine whether an integer is a palindrome. Do this without extra space.class Solution {public: bool isPalindrome(int x) { int d = x; int a = 0; if (x >= 0) while (x != 0) { a原创 2016-08-06 21:42:38 · 171 阅读 · 0 评论