![](https://img-blog.csdnimg.cn/20181216195608574.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode--Java版
LeetCode个人总结
James Shangguan
Standing on Shoulders of Giants
展开
-
贪心算法习题讲解
实验室的算法课程,今天轮到我给师弟师妹们讲贪心算法,顺便也复习一下。贪心算法这个名字听起来唬人,其实通常是比较简单的。虽然通常贪心算法的实现非常容易,但是,一个问题是否能够使用贪心算法,是一定要小心的。本文课通过LeetCode的一些习题,我们来回顾一下贪心算法。原创 2019-05-21 15:42:14 · 1649 阅读 · 1 评论 -
LeetCode重建二叉树系列问题总结
二叉树天然的递归特性,使得我们可以使用递归算法对二叉树进行遍历和重建。之前已经写过LeetCode二叉树的前序、中序、后序遍历(递归实现),那么本文将进行二叉树的重建,经过对比,会发现二者有着许多相似之处。原创 2019-02-27 11:30:58 · 730 阅读 · 0 评论 -
LeetCode栈的基础操作系列问题详细总结
本文总结LeetCode中考察栈的基础操作系列问题。原创 2018-11-13 14:36:42 · 640 阅读 · 3 评论 -
LeetCode 70. Climbing Stairs斐波那契系列问题解析
本文记录解决LeetCode 70. Climbing Stairs(爬台阶)斐波那契系列问题的方法,递归法和迭代法。原创 2018-11-01 15:16:30 · 552 阅读 · 2 评论 -
由LeetCode 581. Shortest Unsorted Continuous Subarray引发的对数组的深入思考(值&引用,复制数组)
本文是由LeetCode 581. Shortest Unsorted Continuous Subarray引发的对数组的一些深入思考,包括对对象、值、引用的理解和复制数组的基本操作原创 2018-10-25 14:49:59 · 545 阅读 · 1 评论 -
LeetCode 206. Reverse Linked List(反转链表)两种方法实现
本文用两种方法实现链表的反转(LeetCode 206. Reverse Linked List):①利用next指针穿针引线;②递归算法。原创 2018-10-18 15:14:23 · 646 阅读 · 0 评论 -
LeetCode 657. Robot Return to Origin(Java相同类型的包装类对象之间值的比较需要注意的地方)
本文旨在分享刷LeetCode 657. Robot Return to Origin时遇到的大坑:Java相同类型的包装类对象之间值的比较问题。原创 2018-10-17 14:48:33 · 647 阅读 · 0 评论 -
LeetCode 167. Two Sum II - Input array is sorted三种解法对比
本文对比LeetCode 167. Two Sum II - Input array is sorted三种不同的解法并进行优化,抛砖引玉,望各位大佬指教。原创 2018-10-11 19:51:13 · 391 阅读 · 1 评论 -
LeetCode删除数组元素系列问题总结
本文实现从数组中删除元素,提供时间复杂度为O(n),空间复杂度为O(1)的Java版本的基本模板,在模板上修改,可以解决LeetCode中数组删除元素相关的问题,如:27. Remove Element(删除元素),26. Remove Duplicates from Sorted Array(删除排序数组中的重复项),80. Remove Duplicates from Sorted Array...原创 2018-10-10 19:38:20 · 613 阅读 · 0 评论 -
LeetCode二叉树的层序遍历系列问题总结(队列实现)
本文用队列实现二叉树的层序遍历,提供Java版的基本模板,在模板上修改,即可解决LeetCode 102. Binary Tree Level Order Traversal,107. Binary Tree Level Order Traversal II,103. Binary Tree Zigzag Level Order Traversal,199. Binary Tree Right Side View。原创 2018-10-09 11:28:05 · 1045 阅读 · 0 评论 -
LeetCode二叉树的前序、中序、后序遍历(递归实现)
本文用递归算法实现二叉树的前序、中序和后序遍历,提供Java版的基本模板,在模板上稍作修改,即可解决LeetCode144. Binary Tree Preorder Traversal(二叉树前序遍历),94. Binary Tree Inorder Traversal(二叉树中序遍历),145. Binary Tree Postorder Traversal(二叉树后序遍历)。原创 2018-10-08 16:58:27 · 722 阅读 · 0 评论 -
LeetCode刷题100. Same Tree
题目:Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Exa...原创 2018-10-07 18:26:56 · 246 阅读 · 0 评论 -
LeetCode刷题229. Majority Element II
题目描述:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,2,3]Output: [...原创 2018-10-07 14:59:02 · 287 阅读 · 0 评论 -
LeetCode刷题169. Majority Element
题目描述:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element...原创 2018-10-07 12:22:14 · 241 阅读 · 0 评论 -
LeetCode刷题283. Move Zeroes
题目描述:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]解题思路1...原创 2018-10-06 23:46:17 · 242 阅读 · 0 评论 -
LeetCode刷题530. Minimum Absolute Difference in BST
题目描述:Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1Explanati...原创 2018-10-06 21:41:23 · 218 阅读 · 0 评论 -
LeetCode刷题783. Minimum Distance Between BST Nodes
题目描述:Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree.Example :Input: root = [4,2,6,1,3,null,nul...原创 2018-10-06 15:53:54 · 316 阅读 · 0 评论 -
LeetCode 338. Counting Bits的两种超简单方法解析
本文分享两种关于LeetCode 338. Counting Bits超级简单易懂的解法,第一种是使用已有的API,第二种是使用动态规划。原创 2018-10-06 12:28:09 · 415 阅读 · 0 评论 -
LeetCode刷题344. Reverse String
题目描述:Write a function that takes a string as input and returns the string reversed.Example 1:Input: "hello"Output: "olleh"Example 2:Input: "A man, a plan, a canal: Panama"Output: "amana...原创 2018-10-06 11:46:14 · 286 阅读 · 0 评论