摘要:
原题链接: "https://leetcode.com/problems/valid parentheses/description/" 这道题目是括号匹配问题,典型的栈的应用!使用栈可以很轻松的解决之: 阅读全文
摘要:
JDK 中的 Stack 类便是经典的数据结构栈的实现,它继承于线程安全的 Vector 类,而且它自身的线程不安全的方法上也加上了 synchronized 关键字,所以它的内部操作也是线程安全的哦! Stack 类不光提供了栈的基本操作:push 和 pop,它还额外提供了三个方法: 1. pe 阅读全文
摘要:
今天刷算法题目时,使用到了 Java 的内置栈类 Stack,好奇它是怎么实现的,发现它是继承于 Vector 这个类。那么,就先学习下 Vector 这个类的实现吧! Vector 和 ArrayList 的区别大概等同于 HashTable 和HashMap 的区别,即:Vector 是 JDK 阅读全文
摘要:
原题链接: "https://leetcode.com/problems/binary tree level order traversal ii/description/" 这道题目是 "http://www.cnblogs.com/optor/p/8538693.html" 这一道的后续,也是很 阅读全文
摘要:
原题链接: "https://leetcode.com/problems/binary tree level order traversal/description/" 这道题目级别为“Easy”,解答出来也确实容易!直接使用个队列进行递归即可: 阅读全文
摘要:
原题链接: "https://leetcode.com/problems/maximum depth of binary tree/description/" 这道题目级别为“Easy”,也确实是简单! 不废话,直接使用递归实现深度优先搜索即可: 阅读全文
摘要:
原题链接: "https://leetcode.com/problems/symmetric tree/description/" 我的思路 这道题目大意是判断一颗二叉树是否是对称树,我看题目是“Easy”级别的,以为不难呢!然后我写出来如下实现: 大致想法就是利用中序遍历,然后将遍历的节点值放入栈 阅读全文