- 博客(47)
- 资源 (3)
- 收藏
- 关注
原创 LeetCode 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 binary
2015-04-30 17:03:10 551
原创 LeetCode 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,#,#,15,7}, 3 / \ 9 20
2015-04-28 23:36:31 584
转载 《深入剖析Tomcat 》第4章 tomcat的默认连接器
4.1 简介第三章的连接器只是一个学习版,是为了介绍tomcat的默认连接器而写。第四章会深入讨论下tomcat的默认连接器(这里指的是tomcat4的默认连接器,现在该连接器已经不推荐使用,而是被Coyote取代)。 tomcat的连接器是一个独立的模块,可被插入到servlet容器中。目前已经有很多连接器的实现,包括Coyote,mod_jk,mod_jk2,
2015-04-27 15:59:42 863
转载 《深入剖析Tomcat 》第3章 连接器(Connector)
第3章 连接器(Connector)3.1 概述在简介一章里说明了,tomcat由两大模块组成:连接器(connector)和容器(container)。本章将使用连接器来增强application 2的功能。一个支持servlet2.3和2.4规范的连接器必须要负责创建javax.servlet.http.HttpServletRequest和javax.servlet.ht
2015-04-27 14:58:30 833
原创 LeetCode Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f
2015-04-27 14:53:35 563
原创 LeetCode Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.题意:判断两棵树是否一样
2015-04-26 13:04:46 587
原创 LeetCode Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis
2015-04-25 20:40:22 593
原创 深入剖析Tomcat-第二章:一个简单的servlet容器(2)
内容:在上一篇中存在一些安全问题,因为我们需要将request和response想上转型为ServletRequest和ServletResponse,了解这个servlet容器内部工作原理的servlet程序员可以将ServletRequest和ServletResponse分别向下转型然后就能调用Request和Response的parse()和sendStaticResource()了。所以
2015-04-25 15:38:06 720
原创 LeetCode Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2015-04-25 14:34:31 647
原创 深入剖析Tomcat-第二章:一个简单的servlet容器(1)
内容:在上一章的基础上多了对servlet的处理,重点是ServletProcessor1这个类,利用到了URL、URLClassLoader和java反射机制。webroot:public class HttpServer1 { private static final String SHUTDOWN_COMMAND = "/SHUTDOWN"; private boolean sh
2015-04-25 11:19:07 838
原创 LeetCode Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret
2015-04-24 22:48:35 565
原创 深入剖析Tomcat-第一章
--开始学习Tomcat服务器,学习代码,自己注释一下。import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.InetAddress;import java.net.ServerSocket;i
2015-04-24 20:17:42 1059 1
原创 LeetCode Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2015-04-24 10:46:19 606
原创 任务间使用管道进行输入输出
内容:通过输入/输出在线程间进行通信通常很有用。利用PipedWriter类(允许任务向管道写)和PipedReader类(允许不同任务从同一个管道中读取)。下面代码中Sender和Receiver代表了需要相互通信的两个任务。Sender把数据放进Writer,然后休眠一段时间。然而,Receiver没有sleep()和wait()。但当他调用read()时,如果没有更多的数据,管道将阻塞,而普
2015-04-23 22:38:37 755
原创 LeetCode Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3
2015-04-23 16:16:33 603
原创 向指定服务器URL 发送POST方法的请求并用JSON表示
内容:首先服务器返回的是JSON数组,但是利用URL读取后其实返回的都是String,所以我们还要转换为JSON数组,POST的传值是参考网上的。public class HttpRequest { /** * 向指定 URL 发送POST方法的请求 * * @param url * 发送请求的 URL * @p
2015-04-22 23:10:53 6669
原创 LeetCode Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio
2015-04-22 20:31:05 571
转载 两篇文章相似度:TF-IDF与余弦相似性的应用
TF-IDF与余弦相似性的应用(一):自动提取关键词作者: 阮一峰日期: 2013年3月15日这个标题看上去好像很复杂,其实我要谈的是一个很简单的问题。有一篇很长的文章,我要用计算机提取它的关键词(Automatic Keyphrase extraction),完全不加以人工干预,请问怎样才能正确做到?这个问题
2015-04-22 15:54:53 4087
原创 吐司BlockingQueue
有一台机器具有三个任务:一个制作吐司、一个给吐司摸黄油、另一个在抹过黄油的吐司上涂果酱。我们可以通过各个处理过程之间的BlockingQueue来运行这个吐司制作程序。也就说我们可以利用三个阻塞队列LinkedBlockingQueue,一个任务完成后就把这个Toast放到下一个队列中,维护三个队列就能做到了。class Toast { public enum Status {DRY, BU
2015-04-21 23:43:18 756
原创 LeetCode Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2015-04-21 15:40:32 586
转载 每天进步一点点——五分钟理解一致性哈希算法(consistent hashing)
转载请说明出处:http://blog.csdn.net/cywosp/article/details/23397179 一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似。一致性哈希修正了CARP使用的简 单哈希算法带来的问题,使得分布式哈希(DHT)可以在P2P环境中真正
2015-04-20 23:33:22 415
原创 LeetCode Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t
2015-04-16 14:48:33 565
原创 LeetCode Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2015-04-15 23:09:24 616
原创 在1-10000中随机生成100个数
题意:在1-10000中随机生成100个数,1-10000已经放在数组中,要求时间和空间都要O(1)。思路:因为空间要O(1),所以我们可以想到这一定是在原本数组的基础上操作,时间也要O(1)的话,证明我们无法Hash后再判重。所以我们可以这么想用一个指针表示目前已经生成好的随机数,那么这个指针从1开始,每次都从剩下的数中随机取一个和当前指针交换就可以完成了,自己写了代码,有错求指出来。i
2015-04-15 13:22:26 10106
原创 LeetCode Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli
2015-04-14 23:15:38 595
原创 LeetCode Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from
2015-04-13 20:41:28 558
原创 LeetCode Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr
2015-04-13 17:13:12 564
原创 LeetCode Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2015-04-13 09:11:54 504
原创 LeetCode 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 in each of
2015-04-12 14:29:50 503
原创 LeetCode Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.题意:求0,1矩阵中,1构成的最大矩阵。思路:借用了上一题,首先我们先计算出dp[i][j]表示到第i行第j列时,此时这一列的连续1的个数,然后计算每一行
2015-04-12 10:34:18 597
原创 LeetCode Largest Rectangle in Histogram (单调栈)
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o
2015-04-11 21:37:03 1394
原创 LeetCode 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.Given 1->1-
2015-04-10 15:14:08 577
原创 LeetCode 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.题意:删除重复的节点。思路:比较简单。/*
2015-04-10 15:09:39 492
转载 java内存分配和String类型的深度解析
一、引题 在java语言的所有数据类型中,String类型是比较特殊的一种类型,同时也是面试的时候经常被问到的一个知识点,本文结合java内存分配深度分析关于String的许多令人迷惑的问题。下面是本文将要涉及到的一些问题,如果读者对这些问题都了如指掌,则可忽略此文。 1、java内存具体指哪块内存?这块内存区域为什么要进行划分?是如何划分的?划分之后每块区域的作用是什
2015-04-10 10:40:59 409
原创 LeetCode Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the
2015-04-10 10:01:13 459
原创 LeetCode Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,
2015-04-08 16:54:47 509
原创 LeetCode Submission Details
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 vertically
2015-04-08 10:57:04 1273
原创 LeetCode Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa
2015-04-07 21:07:11 587
转载 Java 理论与实践: 正确使用 Volatile 变量
volatile 变量使用指南Java™ 语言包含两种内在的同步机制:同步块(或方法)和 volatile 变量。这两种机制的提出都是为了实现代码线程的安全性。其中 Volatile 变量的同步性较差(但有时它更简单并且开销更低),而且其使用也更容易出错。在这期的 Java 理论与实践 中,Brian Goetz 将介绍几种正确使用 volatile 变量的模式,并针对
2015-04-07 20:32:08 365
原创 LeetCode Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2015-04-07 16:38:30 536
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人