![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 71
xiaozhuaixifu
这个作者很懒,什么都没留下…
展开
-
【LeetCode】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原创 2013-10-19 14:02:01 · 1311 阅读 · 0 评论 -
【LeetCode OJ】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 using原创 2013-10-21 13:17:40 · 2663 阅读 · 0 评论 -
【LeetCode】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 i原创 2013-10-30 15:23:10 · 7363 阅读 · 3 评论 -
【LeetCode】 Subsets Subsets II
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,原创 2013-10-29 15:43:32 · 1289 阅读 · 0 评论 -
【LeetCode】 Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2013-10-31 18:58:26 · 1421 阅读 · 0 评论 -
【LeetCode】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 / \原创 2013-10-31 14:36:39 · 1942 阅读 · 0 评论 -
【LeetCode】 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?解法一: 哈希,需要O(n)的空间复杂度,时间复杂度是O(n)/**原创 2013-11-01 14:44:38 · 3138 阅读 · 7 评论 -
【LeetCode】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 o原创 2013-11-04 13:24:03 · 2474 阅读 · 0 评论 -
【LeetCode】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,原创 2013-11-04 11:03:00 · 950 阅读 · 0 评论 -
【LeetCode】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?java code : 很简单的判断单链表是否有环。/** * Definition for singly-linked list. * class原创 2013-10-29 22:21:57 · 2519 阅读 · 0 评论 -
【LeetCode】Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.java code : 预处理出最短串与任意一字符串的公共前缀,用StringBuilder保存,再去遍历剩余字符串,从尾处开始推。复杂度O(m * n) m : length of the arrays, n :le原创 2013-10-29 17:01:43 · 966 阅读 · 0 评论 -
【LeetCode OJ】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原创 2013-10-26 20:35:41 · 889 阅读 · 0 评论 -
【LeetCode】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 exact原创 2013-10-27 10:48:49 · 1046 阅读 · 0 评论 -
【LeetCode】Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2013-10-20 20:20:53 · 1676 阅读 · 0 评论 -
【LeetCodeOJ】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原创 2013-10-20 23:12:42 · 963 阅读 · 0 评论 -
【LeetCode】Search in Rotated Sorted Array
Suppose a sorted array 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 array return it原创 2013-10-27 13:06:58 · 1060 阅读 · 0 评论 -
【LeetCode OJ】Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extr原创 2013-10-22 13:09:41 · 1263 阅读 · 0 评论 -
【LeetCode OJ】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原创 2013-10-22 18:52:42 · 1532 阅读 · 0 评论 -
【LeetCode】Trapping Rain Water 2013年美团网校园招聘研发工程师笔试题
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],原创 2013-10-29 22:07:30 · 1194 阅读 · 0 评论 -
【LeetCode】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.java code :/** * Definition for singly-linked list. * public class ListNode { *原创 2013-11-04 10:21:34 · 1024 阅读 · 0 评论 -
【LeetCode】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原创 2013-11-05 15:50:15 · 2442 阅读 · 0 评论 -
【LeetCode】Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2013-11-05 15:16:52 · 975 阅读 · 0 评论 -
【LeetCode】Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an原创 2014-05-03 15:18:57 · 804 阅读 · 0 评论 -
【LeetCode】LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:get and set.get(key) - Get the value (will always be positive) of the key if t原创 2014-05-19 08:54:49 · 920 阅读 · 0 评论 -
【LeetCode】Reorder List
zhuhttp://www.programcreek.com/2013/12/in-place-reorder-a-singly-linked-list-in-java/转载 2014-05-19 15:55:26 · 668 阅读 · 0 评论 -
【LeetCode】Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-05-19 20:20:17 · 853 阅读 · 0 评论 -
【LeetCode】Pow(x, n)
Implement pow(x, n).思路:快速幂运算,需要考虑指数为负数,同时底数为0的情况,这种属于异常数据,代码里没有体现。class Solution {public: double pow_abs(double x, unsigned int n) { if (n == 0) { return 1;原创 2014-08-04 20:49:46 · 898 阅读 · 0 评论 -
【LeetCode】Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for binary tree * struct TreeNode {原创 2014-08-01 16:47:06 · 963 阅读 · 0 评论 -
【LeetCode】Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t原创 2014-08-07 17:16:02 · 1064 阅读 · 0 评论 -
【LeetCode】Partition List
Given a linked list and a value x, partition it such that all nodes less thanx come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2014-08-01 11:26:35 · 844 阅读 · 0 评论 -
【LeetCode】Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+",原创 2014-03-16 10:16:31 · 782 阅读 · 0 评论 -
【LeetCode】Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes a wor原创 2014-03-15 21:01:47 · 1894 阅读 · 0 评论 -
【LeetCode】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原创 2013-11-06 14:01:41 · 2690 阅读 · 0 评论 -
【LeetCode】Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2013-11-06 15:16:49 · 944 阅读 · 0 评论 -
【LeetCode】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原创 2013-11-07 16:18:31 · 1191 阅读 · 0 评论 -
【LeetCode】Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th原创 2013-11-07 20:05:50 · 752 阅读 · 0 评论 -
【LeetCode】Insertion Sort List
Sort a linked list using insertion sort.java code:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val原创 2013-12-03 20:37:20 · 3157 阅读 · 0 评论 -
【LeetCode】Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution is tri原创 2013-12-03 20:59:46 · 848 阅读 · 0 评论 -
【LeetCode】N-Queens II N皇后问题 回溯法
N-Queens IITotal Accepted: 4852 Total Submissions: 16065 Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.原创 2014-03-15 20:46:05 · 1784 阅读 · 0 评论 -
【LeetCode】Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : v原创 2014-03-16 11:22:59 · 836 阅读 · 0 评论