
leetcode
文章平均质量分 58
张荣华_csdn
这个作者很懒,什么都没留下…
展开
-
正则表达式匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.方法一:C语言bool isMatch(char* s, char* p) { if(s==NULL || p==NULL)return false; if(!...原创 2018-05-25 10:39:18 · 369 阅读 · 0 评论 -
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 ord...原创 2018-05-25 17:25:11 · 211 阅读 · 0 评论 -
Longest Substring Without Repeating Characters(C++)
Given a string, find the length of the longest substring without repeating characters.class Solution {public: int lengthOfLongestSubstring(string s) { map<char,int> maps; in...原创 2018-05-15 17:15:41 · 463 阅读 · 0 评论 -
Median of Two Sorted Arrays(C++)
class Solution {public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int m=nums1.size(),n=nums2.size(); if((m+n)%2==1) re...原创 2018-05-15 17:20:10 · 471 阅读 · 0 评论 -
Longest Palindromic Substring(C++)
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Exa...原创 2018-05-15 17:24:46 · 697 阅读 · 0 评论 -
ZigZag Conversion(C++)
class Solution {public: string convert(string s, int numRows) { if(numRows==1) return s; int step=2*numRows-2; int n=s.size(); string ret=""; for(in...原创 2018-05-15 17:26:16 · 416 阅读 · 0 评论 -
Reverse Integer(C++)
Given a 32-bit signed integer, reverse digits of an integer.class Solution {public: int reverse(int x) { int ans=0,temp=0; while(x!=0) { temp=ans*10+x%10; ...原创 2018-05-15 17:27:36 · 392 阅读 · 0 评论 -
String to Integer (atoi)(C++)
class Solution {public: int myAtoi(string str) { int n=str.size(); int flag=1,i=0,ret=0; if(n==0) return 0; while(str[i]==' ') i++; if(s...原创 2018-05-15 17:32:14 · 608 阅读 · 0 评论 -
Palindrome Number(C++)
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.class Solution {public: bool isPalindrome(int x) { if(x<0) ...原创 2018-05-15 17:34:05 · 323 阅读 · 0 评论 -
Container With Most Water(C++)
class Solution {public: int maxArea(vector<int>& height) { int l=0,r=height.size()-1; int area=0; while(l<r) { area=max(area,min(height[l],he...原创 2018-05-15 17:38:14 · 285 阅读 · 0 评论 -
Longest Common Prefix(C++)
class Solution {public: string longestCommonPrefix(vector<string>& strs) { int n=strs.size(); string res=""; if(n==0) return res; if(n==1) ...原创 2018-05-16 11:59:33 · 496 阅读 · 0 评论 -
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 t...原创 2018-05-26 11:18:52 · 187 阅读 · 0 评论 -
Search for a Range
Given an array of integers nums 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 tar...原创 2018-05-26 11:20:46 · 183 阅读 · 0 评论 -
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.clas...原创 2018-05-26 11:24:12 · 182 阅读 · 0 评论 -
Valid Sudoku
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contain t...原创 2018-05-26 11:26:58 · 158 阅读 · 0 评论 -
Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read off as "t...原创 2018-05-26 11:30:22 · 183 阅读 · 0 评论 -
Combination Sum
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations incandidates where the candidate numbers sums to target.The same repeated ...原创 2018-05-26 11:33:32 · 171 阅读 · 0 评论 -
Combination Sum II
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidates where the candidate numbers sums to target.Each number in candidates may on...原创 2018-05-26 11:38:19 · 222 阅读 · 0 评论 -
Permutations
Given a collection of distinct integers, return all possible permutations.class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector&...原创 2018-05-26 11:40:10 · 343 阅读 · 0 评论 -
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.class Solution {public: vector<vector<int>> permuteUnique(vector<int>& num...原创 2018-05-26 11:55:09 · 231 阅读 · 0 评论 -
Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix directl...原创 2018-05-26 11:57:17 · 185 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n), which calculates x raised to the power n (xn).Note:-100.0 < x < 100.0n is a 32-bit signed integer, within the range [−231, 231 − 1]class Solution {public: double myPow(do...原创 2018-05-27 09:07:43 · 964 阅读 · 0 评论 -
Group Anagrams
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat",&原创 2018-05-27 09:29:05 · 195 阅读 · 0 评论 -
Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation: [...原创 2018-05-27 09:31:02 · 319 阅读 · 0 评论 -
Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.class Solution {public: vector<int> spiralOrder(vector<vector<int>>& ma...原创 2018-05-27 09:33:05 · 586 阅读 · 0 评论 -
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.Determine if you ar...原创 2018-05-27 09:41:01 · 173 阅读 · 0 评论 -
Reverse Linked List
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL/** * Definition for singly-linked list. * struct ListNode { * int val; ...原创 2018-05-27 12:39:48 · 198 阅读 · 0 评论 -
Remove Linked List Elements
Remove all elements from a linked list of integers that have value val./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x),...原创 2018-05-27 14:02:33 · 164 阅读 · 0 评论 -
3Sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.The solution set must not contain dupli...原创 2018-05-23 13:11:48 · 351 阅读 · 0 评论 -
3Sum Closest
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...原创 2018-05-23 13:13:14 · 146 阅读 · 0 评论 -
Letter Combinations of a Phone Number(C++)
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given...原创 2018-05-23 13:14:49 · 463 阅读 · 0 评论 -
4Sum(C++)
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of tar...原创 2018-05-23 13:16:01 · 405 阅读 · 0 评论 -
Remove Nth Node From End of List(C++)
Given a linked list, remove the n-th node from the end of list and return its head./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int ...原创 2018-05-23 13:17:53 · 250 阅读 · 0 评论 -
Valid Parentheses(C++)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2018-05-23 13:19:30 · 320 阅读 · 0 评论 -
Merge Two Sorted Lists(C++)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListNode ...原创 2018-05-23 13:20:42 · 720 阅读 · 0 评论 -
Generate Parentheses(C++)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.class Solution {public: vector<string> generateParenthesis(int n) { vector<...原创 2018-05-23 13:23:11 · 360 阅读 · 0 评论 -
Swap Nodes in Pairs(c++)
Given a linked list, swap every two adjacent nodes and return its head./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x),...原创 2018-05-24 09:43:32 · 304 阅读 · 0 评论 -
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Example 1:Input: [1,3,null,null,2] 1 / 3 \ 2Output: [3,1,null,null,2] ...原创 2018-06-05 08:07:00 · 197 阅读 · 0 评论 -
Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota...原创 2018-06-05 08:07:26 · 145 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->0->...原创 2018-06-05 08:06:38 · 196 阅读 · 0 评论