Leetcode
6plus
Java源码学习关注我的公众号: Plus技术栈
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
18. 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原创 2017-05-03 12:43:35 · 276 阅读 · 0 评论 -
21. 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.水题自己写的classSolut原创 2017-07-28 16:21:16 · 314 阅读 · 0 评论 -
75. 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 in原创 2017-07-28 15:06:58 · 605 阅读 · 0 评论 -
格雷码的算法实现
在正序的基础上将1左移n-1位,再加在逆序上,即得green code 格雷码。算法返回的是10进制的值class Solution {public: vector grayCode(int n) { vector res; res.push_back(0); int inc=1; for(int i=0原创 2017-07-27 15:14:08 · 1828 阅读 · 0 评论 -
90. Subsets II 子集列举
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a solutio原创 2017-07-27 09:21:38 · 256 阅读 · 0 评论 -
40. Combination Sum II
题目Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the原创 2017-05-25 09:20:27 · 262 阅读 · 0 评论 -
48. 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?分析顺时针旋转90,可以看做是沿副对角线翻折一次,然后水平翻折一次原创 2017-05-25 09:56:17 · 250 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array(easy)
题目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 pl原创 2017-05-03 16:37:15 · 319 阅读 · 0 评论 -
11. 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,原创 2017-05-03 14:32:10 · 214 阅读 · 0 评论 -
16. 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原创 2017-05-03 16:25:20 · 294 阅读 · 0 评论 -
15. 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原创 2017-05-03 15:00:01 · 272 阅读 · 0 评论 -
86. Partition List
题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes i原创 2017-07-28 20:09:55 · 267 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
题目Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the ans原创 2017-05-03 10:03:10 · 229 阅读 · 0 评论 -
134. 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原创 2017-05-02 19:40:16 · 217 阅读 · 0 评论 -
55. 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.Det原创 2017-05-01 16:16:58 · 248 阅读 · 0 评论 -
57. 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.Example原创 2017-12-16 12:37:30 · 265 阅读 · 0 评论 -
56. Merge Intervals
题目Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].解析题意:将一个Interval新结构进行合并 关键点在于每次比较用的是ret中的尾Interval。代码/**原创 2017-12-16 12:06:46 · 270 阅读 · 0 评论 -
5. 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.原创 2017-11-27 18:34:38 · 235 阅读 · 0 评论 -
51. N-Queens
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens原创 2017-08-04 16:01:26 · 332 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "原创 2017-11-25 19:50:12 · 202 阅读 · 0 评论 -
2. 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原创 2017-11-25 19:03:42 · 203 阅读 · 0 评论 -
1. Two Sum
QGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use th原创 2017-02-28 20:02:43 · 280 阅读 · 0 评论 -
50. Pow(x, n)
题目Implement pow(x, n).Example 1:Input: 2.00000, 10 Output: 1024.00000 Example 2:Input: 2.10000, 3 Output: 9.26100解析题意:实现幂运算 分析:主要考察利用二分降低运算时间复杂度,注意当n=INT_MIN时的边界处理,INT_MIN的绝对值比INT_MAX的绝对值大一代码class原创 2017-12-12 22:48:44 · 336 阅读 · 0 评论 -
103. Binary Tree Zigzag Level Order Traversal
题目Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given原创 2017-04-25 20:23:53 · 367 阅读 · 0 评论 -
53. Maximum Subarray 最大子序列和
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-原创 2017-08-01 20:00:56 · 222 阅读 · 0 评论 -
剑指offer:二叉搜索树与双向链表非递归与递归解法
题目输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。解析主要利用中序便利,通过设置一个结点变量记录前一个结点进行变换 需熟练掌握树中序遍历的递归与非递归写法代码非递归,主要利用栈/*struct TreeNode { int val; struct TreeNode *left; struct TreeNo原创 2018-01-05 09:32:39 · 554 阅读 · 0 评论 -
61. Rotate List
题目Given a list, rotate the list to the right by k places, where k is non-negative.Example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.解析题意是让旋转一个链表,一开始想到的是快慢指针,但是实现之后发现十分的麻烦,有许多指针移动的操原创 2017-12-17 16:05:27 · 237 阅读 · 0 评论 -
Weekly Contest 63
Min Cost Climbing StairsShortest Completing WordNumber Of Corner RectanglesContain Virus746. Min Cost Climbing Stairs 难度:esayOn a staircase, the i-th step has some non-negative cost cost[i] assig原创 2017-12-17 12:57:27 · 459 阅读 · 0 评论 -
116. Populating Next Right Pointers in Each Node
题目Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next righ原创 2017-05-01 15:48:58 · 228 阅读 · 0 评论 -
113. 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原创 2017-04-30 19:33:11 · 235 阅读 · 0 评论 -
112. 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原创 2017-04-30 17:56:03 · 3168 阅读 · 0 评论 -
LeetCode(110)Balanced Binary Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ cl转载 2017-04-30 14:31:59 · 277 阅读 · 0 评论 -
111. 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.翻译给定二叉树,找到最小深度。最转载 2017-04-30 14:29:06 · 234 阅读 · 0 评论 -
105. Construct Binary Tree from Preorder and Inorder Traversal
题目Given preorder and inorder traversal of a tree, construct the binary tree翻译根据前序遍历和中序遍历重建二叉树分析将之前在数据结构上所学的通过前序和中序写出二叉树融入进来1.确定根节点,然后以根节点来进行递归,前序遍历的根节点为第一个。2.求解树的子树,中序遍历中根左边为左子树,右边原创 2017-04-29 10:49:31 · 310 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree Add to List DescriptionHintsSubmissions
题目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.翻译给定一个二叉树,找到其最大深度。原创 2017-04-25 21:02:36 · 268 阅读 · 0 评论 -
49. Group Anagrams
题目Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"] ] Note: All input原创 2017-12-12 22:40:03 · 219 阅读 · 0 评论 -
102. 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,null,null,15,7], 3 /原创 2017-04-25 16:41:42 · 265 阅读 · 0 评论 -
101. 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原创 2017-04-23 20:26:24 · 237 阅读 · 0 评论 -
100. Same Tree
题目Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.翻译原创 2017-04-20 17:52:39 · 211 阅读 · 0 评论 -
98. 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'原创 2017-04-18 16:13:49 · 232 阅读 · 0 评论
分享