![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 60
ifwantwill
这个作者很懒,什么都没留下…
展开
-
Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?** * Definition for singly-linked list. * struct ListNode { * int val; * Lis原创 2014-02-26 21:51:03 · 428 阅读 · 0 评论 -
Linked List Cycle II
class Solution {public: ListNode *detectCycle(ListNode *head) { ListNode* slow = head; ListNode* fast = head; while (NULL != fast && NULL != fast->next) { slow = slow->next; fast原创 2014-02-27 14:51:51 · 357 阅读 · 0 评论 -
Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to原创 2014-02-27 18:39:52 · 394 阅读 · 0 评论 -
Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2014-02-27 22:30:06 · 374 阅读 · 0 评论 -
Copy List with Random Pointer (deep copy)
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.class Solution {public: Rand原创 2014-02-28 11:53:35 · 507 阅读 · 0 评论 -
Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on原创 2014-03-02 11:12:29 · 420 阅读 · 0 评论 -
Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea原创 2014-03-02 16:18:52 · 284 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity.class Solution {public: ListNode *sortList(ListNode *head) { if (0 == head || 0 == head->next) return head; Lis原创 2014-03-05 15:44:41 · 423 阅读 · 0 评论 -
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原创 2014-03-04 14:52:30 · 377 阅读 · 0 评论 -
Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2014-03-12 02:08:50 · 360 阅读 · 0 评论 -
Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2014-03-15 01:37:43 · 350 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *原创 2014-03-28 07:27:45 · 289 阅读 · 0 评论 -
Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from原创 2014-03-28 08:11:25 · 309 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.class Solution {public: TreeNode *sortedListToBST(ListNode *head) { if (0 == hea原创 2014-03-28 08:12:50 · 299 阅读 · 0 评论 -
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m原创 2014-04-14 03:52:34 · 255 阅读 · 0 评论 -
Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]原创 2014-04-14 06:15:24 · 247 阅读 · 0 评论 -
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?原创 2014-04-13 15:37:34 · 302 阅读 · 0 评论 -
Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2014-03-29 04:06:35 · 288 阅读 · 0 评论 -
Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.class Solution {public: st原创 2014-04-30 07:40:19 · 238 阅读 · 0 评论 -
Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3原创 2014-03-29 06:52:01 · 325 阅读 · 0 评论 -
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原创 2014-04-15 13:18:26 · 256 阅读 · 0 评论 -
Unique Paths
A 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 is trying to reach the原创 2014-04-15 04:09:07 · 280 阅读 · 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-04-15 06:09:58 · 302 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2014-04-15 09:01:36 · 281 阅读 · 0 评论 -
Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X转载 2014-03-29 14:24:29 · 292 阅读 · 0 评论 -
Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {public: void rotate(vector > &原创 2014-04-30 09:22:20 · 302 阅读 · 0 评论 -
Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2014-04-16 02:55:29 · 288 阅读 · 0 评论 -
Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2014-04-16 08:14:35 · 294 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2014-04-16 07:34:00 · 281 阅读 · 0 评论 -
Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb原创 2014-05-01 03:12:38 · 297 阅读 · 0 评论 -
Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2014-03-20 06:37:50 · 324 阅读 · 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./** * Definition for binary原创 2014-03-20 09:04:02 · 276 阅读 · 0 评论 -
Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2014-03-20 08:16:31 · 329 阅读 · 0 评论 -
Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-03-21 05:48:59 · 298 阅读 · 0 评论 -
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-05-01 06:49:06 · 292 阅读 · 0 评论 -
Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in Cwhere the candidate numbers sums to T.Each number in C may only be used once in the combinat原创 2014-05-01 03:53:56 · 227 阅读 · 0 评论 -
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原创 2014-05-01 02:20:33 · 662 阅读 · 0 评论 -
Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2014-03-21 08:34:00 · 282 阅读 · 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原创 2014-03-21 04:07:38 · 244 阅读 · 0 评论 -
Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E原创 2014-04-17 02:54:32 · 282 阅读 · 0 评论