![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
Guo_Xiaoxi
这个作者很懒,什么都没留下…
展开
-
LeetCode38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the原创 2017-03-27 16:28:07 · 308 阅读 · 0 评论 -
LeetCode66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are st原创 2017-04-06 19:50:45 · 234 阅读 · 0 评论 -
LeetCode66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are st原创 2017-04-06 21:12:34 · 289 阅读 · 0 评论 -
LeetCode67. Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.#include<string>#include<cstdlib>#include<iostream>using namespace std;class Solution原创 2017-04-06 21:19:33 · 326 阅读 · 0 评论 -
LeetCode15. 3Sum
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 duplic原创 2017-04-17 09:16:17 · 362 阅读 · 0 评论 -
LeetCode16. 3Sum Closest
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 exactly原创 2017-04-17 10:50:56 · 317 阅读 · 0 评论 -
LeetCode18. 4Sum
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 set mu原创 2017-04-20 19:54:14 · 384 阅读 · 0 评论 -
LeetCOde19. Remove Nth Node From End of List
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 linked list be原创 2017-04-20 20:39:33 · 249 阅读 · 0 评论 -
LeetCode24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no原创 2017-04-21 09:28:12 · 337 阅读 · 0 评论 -
LeetCode25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of nod原创 2017-04-21 11:27:36 · 269 阅读 · 0 评论 -
LeetCode31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible orde原创 2017-04-21 21:04:01 · 301 阅读 · 0 评论 -
LeetCOde33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the ar原创 2017-04-22 10:43:34 · 280 阅读 · 0 评论 -
LeetCode34. Search for a Range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is原创 2017-04-22 11:18:46 · 257 阅读 · 0 评论 -
LeetCode42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], ret原创 2017-04-22 13:33:58 · 352 阅读 · 0 评论 -
LeetCode575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these原创 2017-05-07 15:02:53 · 396 阅读 · 0 评论 -
LeetCode567. 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.Example 1原创 2017-05-07 15:04:59 · 340 阅读 · 0 评论 -
LeetCode101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2017-05-07 15:58:43 · 266 阅读 · 0 评论 -
LeetCode104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.递归/** * Definition for a binary tree node.原创 2017-05-07 17:01:45 · 338 阅读 · 0 评论 -
LeetCode58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as原创 2017-04-06 18:49:12 · 244 阅读 · 0 评论 -
LeetCode17. 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 string “23”原创 2017-04-17 20:45:46 · 407 阅读 · 0 评论 -
LeetCode14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.运行时间 3ms#include<string>#include<vector>#include<iostream>using namespace std;class Solution {public: stri原创 2017-03-27 17:00:33 · 282 阅读 · 0 评论 -
LeetCode2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-03-27 20:53:16 · 242 阅读 · 0 评论 -
LeetCode5. 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. Example:Input:原创 2017-03-28 21:19:56 · 235 阅读 · 0 评论 -
LeetCode6. 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 N A P L S I I G原创 2017-03-28 22:06:01 · 371 阅读 · 0 评论 -
LeetCode11. Container With Most Water
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, 0). Find two lin原创 2017-03-29 13:15:51 · 271 阅读 · 0 评论 -
LeetCode70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive inte原创 2017-04-09 09:44:07 · 226 阅读 · 0 评论 -
LeetCode83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3./** * Definition for singly-lin原创 2017-04-09 10:27:55 · 221 阅读 · 0 评论 -
LeetCode88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional原创 2017-04-10 14:24:26 · 243 阅读 · 0 评论 -
LeetCode9、Palindrome Number
#include<vector>#include<cstdlib>#include<iostream>using namespace std;class Solution {public: bool isPalindrome(int x) { vector<int> v; if(x==0){return true;} if(x<0)原创 2017-03-26 09:09:09 · 364 阅读 · 0 评论 -
LeetCode7. Reverse Integer
1、stackclass Solution {public: int reverse(int x) { if((x==0)||(x==-2147483648)){ return 0; } bool flag=(x<0); x = abs(x); int r; stack原创 2017-03-26 08:46:32 · 320 阅读 · 0 评论 -
LeetCode13. Roman to Integer
给定一个罗马数字s,( I<=s<=MMMCMXCIX)(即1到3999),将罗马数字转换成整数。 如罗马数字I,II,III,IV,V分别代表数字1, 2, 3, 4, 5。 格式: 第一行输入一个罗马数字,接下来输出对应的整数。 提示: 首先要来了解一下罗马数字表示法,基本字符有7个:I,V,X,L,C,D,M,分别表示1,5,10,50,100,500,1000。 在构原创 2017-03-26 10:34:56 · 347 阅读 · 0 评论 -
LeetCode20. Valid Parentheses
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 valid but “原创 2017-03-26 18:53:36 · 317 阅读 · 0 评论 -
LeetCode21. Merge Two Sorted Lists
1、去重了,所以没通过#include<cstdlib>#include<iostream>using namespace std;struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {public: ListNo原创 2017-03-26 21:58:46 · 287 阅读 · 0 评论 -
LeetCode26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with cons原创 2017-03-27 08:46:19 · 239 阅读 · 0 评论 -
LeetCode27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order原创 2017-03-27 10:32:03 · 338 阅读 · 0 评论 -
LeetCode28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 从一个字符串中查找给定字符串第一次出现的位置#include<string>#include<iostream>using namespace s原创 2017-03-27 12:22:10 · 272 阅读 · 0 评论 -
LeetCode35. 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.Here原创 2017-03-27 13:44:29 · 247 阅读 · 0 评论 -
LeetCode107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree [3,9,20,null,null,15,7],原创 2017-05-07 21:33:07 · 325 阅读 · 0 评论