![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 63
随心而动随意而行
time waits no man
展开
-
First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant原创 2014-03-21 10:47:52 · 467 阅读 · 0 评论 -
Reverse Nodes in k-Group
Reverse Nodes in k-Group Total Accepted: 4454 Total Submissions: 18797My SubmissionsGiven a linked list, reverse the nodes of a linked list k at a time and return its modified list.If原创 2014-02-12 23:51:43 · 505 阅读 · 0 评论 -
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:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-02-11 20:18:23 · 449 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.时间复杂度:O(nlogk),合并k个链表,总共n个元素.(考察多路归并)class Solution { //小->大public: void keepHeap(vector&ve原创 2014-02-11 21:24:34 · 488 阅读 · 0 评论 -
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 va原创 2014-02-11 19:37:01 · 490 阅读 · 0 评论 -
Sort List
Sort List Total Accepted: 4796 Total Submissions: 24553My SubmissionsSort a linked list in O(n log n) time using constant space complexity.class Solution {public: ListNode *sortLis原创 2014-02-11 18:53:00 · 469 阅读 · 0 评论 -
Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the原创 2014-02-11 08:20:08 · 495 阅读 · 0 评论 -
Unique Paths
Unique PathsA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot原创 2014-02-10 17:15:18 · 526 阅读 · 0 评论 -
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原创 2014-02-10 22:14:56 · 475 阅读 · 0 评论 -
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:Elements in a triplet (a,b,c原创 2014-02-10 20:34:58 · 491 阅读 · 0 评论 -
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原创 2014-02-10 19:56:43 · 449 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array Total Accepted: 8534 Total Submissions: 26405My SubmissionsGiven a sorted array, remove the duplicates in place such that each element appear only onc原创 2014-02-13 09:08:44 · 457 阅读 · 0 评论 -
Swap Nodes in Pairs
Swap Nodes in Pairs Total Accepted: 7124 Total Submissions: 22383My SubmissionsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, yo原创 2014-02-12 23:19:26 · 506 阅读 · 0 评论 -
Remove Element
Remove Element Total Accepted: 8010 Total Submissions: 24406My SubmissionsGiven an array and a value, remove all instances of that value in place and return the new length.The order of原创 2014-02-13 09:12:57 · 477 阅读 · 0 评论 -
Pow(x, n)
Pow(x, n)Implement pow(x, n).class Solution {public: double pow(double x, int n) { const int MaxNegative = (~((unsigned int) 0))>>1; int flag = 0; unsigned int exp原创 2014-03-15 21:46:00 · 557 阅读 · 0 评论 -
Valid Sudoku
Valid Sudoku Total Accepted: 4240 Total Submissions: 15658My SubmissionsDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially fil原创 2014-02-15 10:49:29 · 576 阅读 · 0 评论 -
Valid Sudoku
Valid Sudoku Total Accepted: 4240 Total Submissions: 15658My SubmissionsDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially fil原创 2014-02-15 10:48:42 · 601 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node Total Accepted: 8021 Total Submissions: 23241My SubmissionsGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; Tree原创 2014-02-15 08:30:53 · 505 阅读 · 0 评论 -
Triangle
Triangle Total Accepted: 5686 Total Submissions: 21968My SubmissionsGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row原创 2014-02-14 20:57:08 · 548 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.方法一:从根节点开始计数,直到叶子节点,寻找最短路径./**原创 2014-02-26 08:39:09 · 485 阅读 · 0 评论 -
Merge Two Sorted Lists
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.思路:向一个已经排序好的链表插入某个节点,该链表依旧保持排序好的状态./*原创 2014-02-26 08:05:12 · 538 阅读 · 0 评论 -
Insertion Sort List
Sort a linked list using insertion sort.Have you been asked this question in an interview? YesDiscuss思路:把原链表分为两个链表:待插入链表和已排序链表.开始时候是将原链表头分出去作为已排序链表,剩下的作为带插入链表,然后每次将原创 2014-02-25 16:08:19 · 520 阅读 · 0 评论 -
Implement strStr()
Implement strStr() Total Accepted: 5907 Total Submissions: 29160My SubmissionsImplement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is n原创 2014-02-13 08:44:15 · 468 阅读 · 0 评论 -
Edit Distance
Edit Distance Total Accepted: 4550 Total Submissions: 18687My SubmissionsGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each opera原创 2014-02-12 23:02:46 · 506 阅读 · 0 评论 -
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:Element原创 2014-02-10 20:33:06 · 464 阅读 · 0 评论 -
Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return原创 2014-02-10 15:29:01 · 479 阅读 · 0 评论 -
Reverse Integer
计算int最大值:const intmax=(unsigned int)(~0)>>1; 移位操作符:>对于无符号来说:补0,左移右边补零,右移左边补0;对于有符号来说:补0,左移右边0,右移左边补补最高有效位;Reverse digitsof an integer.Example1: x = 123, return 321Example2: x = -原创 2014-02-05 11:06:09 · 473 阅读 · 0 评论 -
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原创 2014-02-04 16:04:56 · 489 阅读 · 0 评论 -
Maximum Depth of Binary Tree
Given a binarytree, find its maximum depth.The maximumdepth is the number of nodes along the longest path from the root node down tothe farthest leaf node./** * Definitionfor binary tree * s原创 2014-02-05 22:38:25 · 419 阅读 · 0 评论 -
Longest Palindromic Substring
Given a string S, find the longest palindromic substringin S. You mayassume that the maximum length of S is 1000, and there exists one uniquelongest palindromic substring. classSolution {pu原创 2014-02-03 11:54:29 · 486 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given astring, find the length of the longest substring without repeating characters.For example, the longest substring without repeating letters for"abcabcbb" is "abc", which the length is 3. For"bbb原创 2014-02-03 09:29:52 · 450 阅读 · 0 评论 -
ZigZag Conversion
The string "PAYPALISHIRING" is written in azigzag pattern on a given number of rows like this: (you may want to displaythis pattern in a fixed font for better legibility)P A H NA P L S I I G原创 2014-02-03 09:32:07 · 489 阅读 · 0 评论 -
Add Two Numbers
You are giventwo linked lists representing two non-negative numbers. The digits are storedin reverse order and each of their nodes contain a single digit. Add the twonumbers and return it as a linked原创 2014-02-03 09:31:24 · 433 阅读 · 0 评论 -
Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).翻译: 有两个已经排序的数组A,B,他们的大小分别是原创 2014-02-01 17:27:17 · 526 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-02-03 18:10:46 · 458 阅读 · 0 评论 -
Two Sum
Given an arrayof integers, find two numbers such that they add up to a specific targetnumber.The functiontwoSum should return indices of the two numbers such that they add up to thetarget, where i原创 2014-02-03 09:29:17 · 551 阅读 · 0 评论 -
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire rowand column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using原创 2014-02-05 10:34:39 · 605 阅读 · 0 评论 -
Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution {publi原创 2014-02-07 12:30:18 · 441 阅读 · 0 评论 -
Jump Game II
Given an array of non-negative integers, you are initiallypositioned at the first index of the array.Each element in the array represents your maximum jump length atthat position.Your goal is原创 2014-02-05 22:36:43 · 438 阅读 · 0 评论 -
Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].class Solution原创 2014-02-10 10:44:00 · 3043 阅读 · 0 评论