自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(56)
  • 资源 (1)
  • 收藏
  • 关注

原创 Web浏览器中的JavaScript---客户端JavaScript

客户端JavaScript在Web浏览器中,一些呈现静态信息的页面叫做文档。相对于文档来说,其他Web页面则可以成为Web应用。这些页面可以动态载入新的信息,因此看起来更加图形化;并且他们能进行离线操作,以及保存数据库到本地。还有一些Web页面处于文档和应用之间,他们结合了两者的特性。这就是在Web浏览器中如何呈现Web页面的。Window对象是所有客户端JavaScript特性和API的主要接入点

2017-08-24 20:09:51 805

原创 Maven 使用不成熟指南

安装与环境

2017-08-17 13:46:48 362

原创 Thymeleaf

标准表达式语法变量表达式语法:${...}例如:<span th:text=${book.author.name}>...</span>含义:将${book.author.name}的值赋给th:text这个属性消息表达式语法:#{...}例如:<span th:text=#{header.address.city}>...</span>含义:将${header.address.cit

2017-08-16 15:58:40 386

原创 Java Concurrency in Practice ---对象的共享

这一小节主要讲如何共享和发布对象。2.1 可见性可见性指的是在多线程中,如果一个线程对某个变量做出了改变,其他线程要能够看得见这种改变。首先,来看一个没有同步机制的共享变量的例子:public class NoVisibility { private static boolean ready; private static int number; private static

2016-12-02 13:15:18 369

原创 Java Concurrency in Practice ---线程安全性

1. 什么是线程安全性当多个线程访问某个类时,这个类始终都能表现出正确的行为,那么就称这个类是线程安全的。再解释一下就是: 当多个线程访问某个类时,不管运行时环境采用何种调度方式或者这些线程将如何交替执行,并且在主调代码中不需要任何额外的同步或协同,这个类都能表现出正确的行为,那么就称这个类是线程安全的。无状态对象一定是线程安全的,而大多数 Servlet 都是无状态的,从而极大地降低了在实现

2016-12-01 18:08:40 420

原创 Symmetric Tree ---LeetCode

https://leetcode.com/problems/symmetric-tree/解题思路:这道题是判断一棵树是不是对称树。显而易见可以用递归实现,递归判断左子树的左子节点是否等于右子树的右子节点,左子树的右子节点是否等于右子树的左子节点。这个思路就很类似于 Same Tree。/** * Definition for a binary tree node. * public class

2016-11-30 21:57:07 272

原创 LeetCode Summary II ---Tree

Part 1:Traversal Binary TreeBinary Tree Preorder Traversal Binary Tree Inorder Traversal Binary Tree Postorder Traversal Binary Tree Level Order Traversal Binary Tree Level Order Traversal II Bina

2016-11-30 21:53:52 359

原创 Populating Next Right Pointers in Each Node II ---LeetCode

https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/解题思路:和 Populating Next Right Pointers in Each Node 这题类似,只是将题目要求任意化,不再局限为仅仅给一棵左右子树高度相等的二叉树。这时我们需要多判断一下它是否具有左右子节点即可。/** * Def

2016-11-30 13:59:45 336

原创 Sum of Left Leaves ---LeetCode

https://leetcode.com/problems/sum-of-left-leaves/解题思路:思路就是遍历整棵树,遇到左子节点的叶子节点就记录下来,最后输出整个结果。这里有递归和迭代两种方法,要注意下细节。solution 1 : recursive/** * Definition for a binary tree node. * public class TreeNode {

2016-11-29 22:51:25 331

原创 Same Tree ---LeetCode

https://leetcode.com/problems/same-tree/解题思路:姑且认为有这么几种情况下两棵树是不相等的,一是长度不等,而是节点的值不等。所以我们用递归,如果都躲过了这两个条件直到遍历到叶子节点,那么这两棵树就是相等的。/** * Definition for a binary tree node. * public class TreeNode { * in

2016-11-29 22:18:46 387

原创 Populating Next Right Pointers in Each Node ---LeetCode

https://leetcode.com/problems/populating-next-right-pointers-in-each-node/解题思路:观察可以发现,每一层从左至右每一个节点依次指向它右边的节点。因此可以用层序遍历 Binary Tree Level Order Traversal 来解决这道题,在遍历到这一层的时候,判断它是不是本层最右的元素,如果不是就指向旁边的元素,如果是

2016-11-29 22:11:44 386

原创 Minimum Depth of Binary Tree ---LeetCode

https://leetcode.com/problems/minimum-depth-of-binary-tree/解题思路:与 Maximum Depth of Binary Tree 这道题相反,是求二叉树的最小深度。贴两种写法:/** * Definition for a binary tree node. * public class TreeNode { * int val

2016-11-29 21:32:01 323

原创 Maximum Depth of Binary Tree ---LeetCode

https://leetcode.com/problems/maximum-depth-of-binary-tree/解题思路:这道题要找出二叉树的最大深度,显而易见用 DFS 来实现,可以递归实现也可以迭代实现。最大深度即比较左子树与右子树的深度,谁大就输出谁。/** * Definition for a binary tree node. * public class TreeNode {

2016-11-29 20:12:26 314

原创 Kth Smallest Element in a BST ---LeetCode

https://leetcode.com/problems/kth-smallest-element-in-a-bst/解题思路:根据 BST 的性质,先序遍历输出的正好是从小到大的升序排列。因此可以用中序遍历来解决这道题。现在回顾一下中序遍历这道题 Binary Tree Inorder Traversal: 维护一个栈,先遍历左子节点,接着遍历右节点。这道题只需要在出栈的时候将 k 自减,直

2016-11-29 18:33:31 402

原创 Invert Binary Tree ---LeetCode

https://leetcode.com/problems/invert-binary-tree/解题思路:这道题需要我们反转二叉树,可以认为是每一层的左右子节点互相交换。涉及到层序遍历,很容易想到维护一个队列,将左右子节点分别入列,接着再交换左右子节点。将队列弹出的节点作为下一次循环的根节点。另外还有好几种方法,可以看看这个链接: https://discuss.leetcode.com/top

2016-11-29 10:59:25 337

原创 Flatten Binary Tree to Linked List ---LeetCode

https://leetcode.com/problems/flatten-binary-tree-to-linked-list/解题思路:遍历一遍树,如果根节点的右子节点不为空,将其入栈,并将左子节点移到右边,左边制空。当移到叶子节点时,再将栈里的节点依次弹出。/** * Definition for a binary tree node. * public class TreeNode {

2016-11-29 10:40:49 461

原创 Count Complete Tree Nodes ---LeetCode

https://leetcode.com/problems/count-complete-tree-nodes/解题思路:题目要求计算一棵完全二叉树的节点数。首先回顾一下完全二叉树: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the

2016-11-28 21:02:43 382

原创 Convert Sorted Array to Binary Search Tree ---LeetCode

https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/解题思路:题目给我们一个已按升序排好的数组,让我们把它转换为一棵高度平衡的二叉查找树。已排好序的数组的中点可以看做根节点,中点左边的数组即为左子树,右边的数组即为右子树,再递归左子树和右子树来构造整棵 BST。/** * Definition for a

2016-11-28 17:58:48 325

原创 Construct Binary Tree from Inorder and Postorder Traversal ---LeetCode

https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/解题思路: http://www.cnblogs.com/grandyang/p/4296193.html/** * Definition for a binary tree node. * public class

2016-11-28 17:45:32 381

原创 Construct Binary Tree from Preorder and Inorder Traversal ---LeetCode

https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/解题思路:由于先序遍历(DLR)可以知道根节点的位置,而中序遍历(LDR)可以知道左子树右子树的位置,就可以用递归来实现。记住并理解递归的参数。举个例子: preorder: [7, 10, 4, 3, 1, 2, 8,

2016-11-28 17:22:42 369

原创 Binary Tree Right Side View ---LeetCode

https://leetcode.com/problems/binary-tree-right-side-view/解题思路:这道题的意思要输出从右边看到的节点元素,即:每一层最右边的那个元素。因此我们可以用队列来实现,遍历每一层时,将最右边的元素入列。需要注意的是:在将左右子树的节点入列时,一定要先入列右节点!/** * Definition for a binary tree node. *

2016-11-28 16:08:59 370

原创 Binary Tree Paths ---LeetCode

https://leetcode.com/problems/binary-tree-paths/解题思路:这道题需要求返回所有从根节点到叶子节点的路径,用递归实现。求路径的题目思想都大差不差,注意细节就好。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNo

2016-11-28 15:52:12 489

原创 Path Sum III ---LeetCode

https://leetcode.com/problems/path-sum-iii/这道题与 Path Sum 与 Path Sum II 的区别在于,这道题不需要遍历到叶子节点再结束,同时也不用从根节点开始记录,只要遇到有相加等于 sum 的节点,就记录下来,最终输出有几条这样的路径。/** * Definition for a binary tree node. * public clas

2016-11-28 14:55:02 317

原创 Path Sum II ---LeetCode

https://leetcode.com/problems/path-sum-ii/解题思路: 和 Path Sum 类似,都是通过递归来找到合适的叶子节点,只是这道题在过程中要记录下满足要求的所有节点。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNo

2016-11-28 12:21:53 329

原创 Path Sum ---LeetCode

https://leetcode.com/problems/path-sum/解题思路:这道题我们通过递归,依次将 sum 的值缩减,最终判断叶子节点是否等于 sum。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tre

2016-11-28 11:41:52 358

原创 Binary Tree Zigzag Level Order Traversal ---LeetCode

https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/解题思路:Binary Tree Level Order Traversal 这道题是每一个水平层都是从左至右的遍历,Binary Tree Level Order Traversal II 是将水平层从下至上的输出,而这道题是奇数层从左至右的遍历,偶数层从右

2016-11-28 11:10:40 245

原创 Binary Tree Level Order Traversal II

https://leetcode.com/problems/binary-tree-level-order-traversal-ii/解题思路: 和 Binary Tree Level Order Traversal 类似,最后将结果反转一下就好。/** * Definition for a binary tree node. * public class TreeNode { *

2016-11-28 10:19:52 274

原创 Binary Tree Level Order Traversal ---LeetCode

https://leetcode.com/problems/binary-tree-level-order-traversal/解题思路:二叉树的层序遍历,即 BFS 的应用。这里我们维护一个队列,遍历节点时,如果它有左右子节点便将左右子节点入列,并且弹出当前节点。队列里即将弹出的节点作为下一轮循环的当前节点,直到队列为空为止。/** * Definition for a binary tree

2016-11-27 23:52:55 314

原创 Binary Tree Postorder Traversal ---LeetCode

https://leetcode.com/problems/binary-tree-postorder-traversal/二叉树的后序遍历,递归调用还是和前面的思路一样。迭代的方法这里使用了两个栈,一个栈用于 前–左–右 的遍历该层时的临时存储栈,另外一个用于存储结果。同时,这两个链接也有很多好的方法,大家一起学习一下。 http://blog.csdn.net/linhuanmars/arti

2016-11-27 23:31:38 329

原创 Binary Tree Preorder Traversal ---LeetCode

https://leetcode.com/problems/binary-tree-preorder-traversal/解题思路:这道题是二叉树的先序遍历,同样有两种基本解法以及一个优化空间的解法: - recursive、iterative - Morris Traversal第三种方法详见 Binary Tree Inorder Traversal。solution 1 : recursi

2016-11-27 22:37:49 243

原创 Binary Tree Inorder Traversal ---LeetCode

https://leetcode.com/problems/binary-tree-inorder-traversal/解题思路:这道题是中序遍历一棵二叉树。首先回顾一下二叉树的遍历: 可以简单分为两种方法,深度优先遍历和广度优先遍历。深度优先遍历:L、D、R分别表示遍历左子树、访问根结点和遍历右子树。先序遍历(preorder traversal)二叉树的顺序是DLR,中序遍历(inorde

2016-11-27 21:13:57 421

原创 Binary Search Tree Iterator

https://leetcode.com/problems/binary-search-tree-iterator/解题思路:首先回顾一下二叉查找树: 二叉查找树(BST)是指一棵空树或者是具有以下性质的树: 任意节点的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 任意节点的左、右子树也分别为

2016-11-27 20:24:53 255

原创 Balanced Binary Tree ---LeetCode

https://leetcode.com/problems/balanced-binary-tree/解题思路:首先回顾一下二叉平衡树: 平衡二叉树(AVL):在AVL树中任何节点的两个子树的高度最大差别为1,所以它也被称为高度平衡树。查找、插入和删除在平均和最坏情况下都是O(log n)。增加和删除可能需要通过一次或多次树旋转来重新平衡这个树。(via Wikipedia)这里使用 getH

2016-11-27 19:43:38 329

原创 LeetCode Summary I ---Linked List

Part 1:Add two numbers Add two numbers II这两道题都是相加类的题,需要维护当前位和进位,第一道是链表倒序存放元素,第二道是正序。正序存放元素的栈的解法需要再熟悉一下。另外需要注意的是:当最高位仍有进位时,需要新建一个节点来接受进位。 同时和数组的这类题 Plus One 一起熟悉熟悉。Part 2:Delete Node in a Linked List

2016-11-27 13:32:14 276

原创 Reorder List ---LeetCode

https://leetcode.com/problems/reorder-list/解题思路: 首先题目要求了要 in-place。表明我们不能创建一个新的链表,而只能通过改变指针的指向来重新排序。一共分为三个步骤解决:使用 slow 和 fast 指针找到链表中点,将链表分为两半。将后半段链表反转。最后将两段链表归并即可。示意图:/** * Definition for singly

2016-11-25 17:30:16 275

原创 Reverse Linked List ---LeetCode

https://leetcode.com/problems/reverse-linked-list/解题思路: 这里使用迭代实现的链表反转,链表反转时需要做两件事,一是将当前节点指向前一个节点,二是移动节点继续迭代。/** * Definition for singly-linked list. * public class ListNode { * int val; *

2016-11-25 16:47:14 279

原创 Remove Nth Node From End of List ---LeetCode

https://leetcode.com/problems/remove-nth-node-from-end-of-list/解题思路: 利用两个指针,slow 和 fast。首先让 fast 指针先走 n 步,这样的话 slow 和 fast 再一起走,直到 fast 等于 null 时 slow 所在的位置刚好的倒数第 n 个节点。但是由于没有 prev 指针的存在,为了我们删除节点的方便,我

2016-11-25 16:03:54 267

原创 Remove Linked List Elements ---LeetCode

https://leetcode.com/problems/remove-linked-list-elements/解题思路: 这道题用一个 dummy node,遍历链表,如果遇到需要删除的元素,就将 prev 指针指向下一个元素就好了。/** * Definition for singly-linked list. * public class ListNode { * int

2016-11-25 15:45:19 297

原创 Remove Duplicates from Sorted List II ---LeetCode

https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/解题思路: 类似于 Remove Duplicates from Sorted List 的思想,只不过本题要求将重复的所有元素都删掉,那么这时我们需要一个 prev 指针来辅助,将 prev 指针指向 curr.next 的过程就能将重复元素都删除。同时,需要一

2016-11-25 15:31:42 376

原创 Remove Duplicates from Sorted List ---LeetCode

https://leetcode.com/problems/remove-duplicates-from-sorted-list/解题思路:遍历链表,遇到与前一个节点相同的值,就让前一个节点指向后一个节点,如果不等就直接移动当前节点继续遍历。/** * Definition for singly-linked list. * public class ListNode { * int

2016-11-25 11:59:19 234

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除