
Template
文章平均质量分 59
zshouyi
这个作者很懒,什么都没留下…
展开
-
Here is a 10-line template that can solve most 'substring' problems
I will first give the solution then show you the magic template. The code of solving this problem is below. It might be the shortest among all solutions provided in Discuss. string minWindow(strin转载 2017-01-08 14:39:45 · 587 阅读 · 0 评论 -
模板:Binary Search - 二分搜索
二分搜索是一种在有序数组中寻找目标值的经典方法,也就是说使用前提是『有序数组』。非常简单的题中『有序』特征非常明显,但更多时候可能需要我们自己去构造『有序数组』。下面我们从最基本的二分搜索开始逐步深入。 模板 - lower/upper bound 定义 lower bound 为在给定升序数组中大于等于目标值的最小索引,upper bound 则为小于等于目标值的最大索引,下面上转载 2017-01-17 08:16:24 · 627 阅读 · 0 评论 -
关于位操作的总结
leetcode上关于位操作的总结:关于位操作的总结转载 2017-02-01 08:29:29 · 229 阅读 · 0 评论 -
JAVA 二叉树遍历
package edu.cumt.jnotnull; import java.util.Stack; public class BinaryTree { protected Node root; public BinaryTree(Node root) { this.root = root; } p转载 2017-03-09 09:06:19 · 313 阅读 · 0 评论 -
二叉树中序遍历解题汇总
Question : Binary Tree Inorder Traversal public ListInteger> inorderTraversal(TreeNode root) { ListInteger> list = new ArrayList<>(); if(root == null) return list; Stack stack = new Stack原创 2017-05-31 09:25:06 · 434 阅读 · 0 评论 -
A clean DP solution which generalizes to k transactions
有一个解决股票买卖问题(Best Time to Buy and Sell Stock)的模板,可以推广到买卖n次。 class Solution { public: int maxProfit(vector &prices) { // f[k, ii] represents the max profit up until prices[ii] (Note: NOT en原创 2017-07-24 13:02:36 · 325 阅读 · 0 评论 -
二叉树遍历模板(前序,中序,后序)
Pre Order Traverse public List preorderTraversal(TreeNode root) { List result = new ArrayList<>(); Deque stack = new ArrayDeque<>(); TreeNode p = root; while(!stack.isEmpty() || p !原创 2017-07-26 05:04:30 · 710 阅读 · 0 评论 -
Morris 二叉搜索树遍历模板
Morris Traversal是o(n)时间复杂度,o(1)空间复杂度的BST遍历方法。 下面是Morris Traversal模板: public void morrisInorderTraverse() { Node cur = root; while (cur != null) { if (cur.left == null) { ...转载 2019-09-08 09:58:42 · 288 阅读 · 0 评论