![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
6plus
Java源码学习关注我的公众号: Plus技术栈
展开
-
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 · 227 阅读 · 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 · 234 阅读 · 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 · 155 阅读 · 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 · 245 阅读 · 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 · 196 阅读 · 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 · 201 阅读 · 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 · 180 阅读 · 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 · 1626 阅读 · 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 · 507 阅读 · 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 · 223 阅读 · 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 · 218 阅读 · 0 评论 -
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 · 210 阅读 · 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 · 176 阅读 · 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 · 208 阅读 · 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 · 137 阅读 · 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 · 135 阅读 · 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 · 258 阅读 · 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 · 167 阅读 · 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 · 200 阅读 · 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 · 179 阅读 · 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 · 194 阅读 · 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 · 158 阅读 · 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 · 201 阅读 · 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 · 251 阅读 · 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 · 169 阅读 · 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 · 221 阅读 · 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 · 3005 阅读 · 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 · 179 阅读 · 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 · 163 阅读 · 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 · 343 阅读 · 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 · 155 阅读 · 0 评论 -
剑指offer:二叉搜索树与双向链表非递归与递归解法
题目输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。解析主要利用中序便利,通过设置一个结点变量记录前一个结点进行变换 需熟练掌握树中序遍历的递归与非递归写法代码非递归,主要利用栈/*struct TreeNode { int val; struct TreeNode *left; struct TreeNo原创 2018-01-05 09:32:39 · 461 阅读 · 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 · 217 阅读 · 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 · 315 阅读 · 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 · 206 阅读 · 0 评论 -
83.Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.class Solu原创 2017-07-28 21:01:58 · 314 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Give原创 2017-07-28 21:03:17 · 306 阅读 · 0 评论 -
链表算法题技巧总结
1.旋转链表,遍历一遍求链表长度,将链表首尾相接再断开(61.rorate)2.将两条排序链表连接,直接连接即可(21.mergetwolist)3.当提示越界时,应该注意左式不为NULL,右式可为NULL,如 p->next==p->next->next条件满足p->next!=NULL即可或者是两次引用成员,如p->next->val,如果p->原创 2017-07-28 21:06:53 · 722 阅读 · 0 评论 -
25. Reverse Nodes in k-Group
题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of...原创 2017-07-29 16:41:58 · 190 阅读 · 0 评论 -
79. 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 v原创 2017-08-07 14:43:50 · 167 阅读 · 0 评论