自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(198)
  • 资源 (3)
  • 收藏
  • 关注

原创 LeetCode 152 - Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest pro...

2015-08-10 07:22:21 80

原创 Java Blocking Queue

A blocking queue is a queue that blocks when you try to dequeue from it and the queue is empty, or if you try to enqueue items to it and the queue is already full. A thread trying to dequeue from an ...

2015-08-05 22:58:46 194

原创 LeetCode 46 - Permutations

Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. public List<List...

2015-08-04 00:36:32 88

原创 LeetCode 160 - Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists:A: a1 → a2 ↘ ...

2015-08-03 23:25:19 82

原创 Linkedin Interview - Isomorphic Strings

Given two strings, determine if they are isomorphic. Two words are called isomorphic if the letters in one word can be remapped to get the second word. Remapping a letter means replacing all occurren...

2015-08-03 23:10:49 71

原创 LeetCode 242 - Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assume the s...

2015-08-03 23:05:16 78

原创 Google Interview - 警察到房间的最短距离

一个 n x n 矩阵,每个房间可能是封闭的房间,可能是警察,可能是开的房间, 封闭的房间不能过,返回一个n x n矩阵,每一个元素是最近的警察到这个房间的最短距离。 初始矩阵中-1代表封闭房间,INT_MAX代表普通房间,0代表有警察的房间。 Solution: 把警察都找出来,然后一起push到BFS的queue里面,同时搜索。复杂度可降为O(n^2)。Starting fro...

2015-08-01 12:58:22 57

原创 HTTP 方法:GET 对比 POST

两种最常用的 HTTP 方法是:GET 和 POST。什么是 HTTP?超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信。HTTP 的工作方式是客户机与服务器之间的请求-应答协议。web 浏览器可能是客户端,而计算机上的网络应用程序也可能作为服务器端。举例:客户端(浏览器)向服务器提交 HTTP 请求;服务器向客户端返回响应。响应包含关于请求的状...

2015-08-01 08:44:35 50

原创 Longest Consecutive 1s in Binary

Find the longest continuous subsequence of 1's in binary representation of an integer.Solution 1: public int countConsecutive1s(int n) { if(n == 0) return 0; int max = 0; int len = 0; ...

2015-07-31 03:23:31 88

原创 LintCode - Search Range in Binary Search Tree

Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x such that k1<=x<=k2 and x is a key of gi...

2015-07-30 23:52:45 51

原创 Google Interview - Flip Game

算法游戏,给一个只有+-两种字符的array,两个玩家,轮到某个玩家他可以任选两个连续的++将他们变成--,如果某个玩家发现对方无法行动则赢得游戏,要求写isWin(String s)判断先行动的玩家能否赢。 Followup 如何优化,时间上和空间上。public boolean canWin(char[] s) { int start = -1; fo...

2015-07-30 14:11:17 45

原创 Implement a Stack

Implement Stack in Java.public class MyStack<E> { private static class Node<E> { E value; Node<E> next; public Node(E v, Node<E> n){ value = v; next = n; }...

2015-07-30 11:56:40 79

原创 Sort Part to Make Entire Array Sorted

Given an unsorted array arr[0..n-1] of size n, find the minimum length subarray arr[s..e] such that sorting this subarray makes the whole array sorted. Examples:1) If the input array is [10, 12, ...

2015-07-30 00:44:53 62

原创 石子合并问题

[问题描述]:  设有n堆石子排成一排,其编号为1、2、3、…、n(n<=100)。每堆石子的数量用:a[1]、a[2]、…、a[n] 表示,现将这n堆石子归并成一堆,归并的规则:◆每次只能将相邻两堆归并成一堆,即:第 1 堆石子 a[1] 只能与第 2 堆石子 a[2] 归并,最后一堆石子 a[n] 只能与 a[n-1] 归并,中间的石子 a[i] 只能与 a[i-1] 或 a[i...

2015-07-29 22:58:44 232

原创 Google Interview - Perimeter of region that has the same color of that point

given grid of colors, coordinate of a point and its color, find the perimeter of the region that has the same color of that point.BFS或DFS,构成perimeter的条件是只要上下左右有一个不是同颜色或者是out of bound 用一个set记录visit的...

2015-07-29 09:48:00 46

原创 Google Interview - Check String Order

given an order string "abc" check if "aabdccd" maintain the order"aabdccd" -> true;"abbca" -> false;note:order does not contain all chars in s public boolean checkOrder(String pat, St...

2015-07-29 09:45:39 53

原创 Airbnb Interview - Nested Integer List Parser

实现一个mini parser, 输入是以下格式的string:"324" or"[123,456,[788,799,833],[[]],10,[]]"要求输出:324 or [123,456,[788,799,833],[[]],10,[]].也就是将字符串转换成对应的格式的数据.输入一个数组的字符串, 要返回一个数组, 里面每一个元素是要么一个整数, 要么是一个数组.但是注意数组可以...

2015-07-26 13:55:05 47

原创 Hedvig Interview - Count of number with no consecutive 1's

Given integer n, find the number of different binary strings of size n where there are no consecutive 1's.Eg: If n is 2, valid strings are 00, 01, 10. You should return 3. 假设f(n, k)是第n位上为k的数字的个数无...

2015-07-22 14:14:01 66

原创 Implementing HashSet in Java

Implementing HashSet in Java. public class HashSet<K> { public static class Node<K> { final K key; Node next; public Node(K key, Node next) { this.key = key; this.n...

2015-07-22 07:59:35 45

原创 LeetCode 141 - Linked List Cycle

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? Solution 1:public boolean hasCycle(ListNode head) { ListNode walker = head, r...

2015-07-21 11:44:35 51

原创 Google Interview - Compress String to i18n

i18n (where 18 stands for the number of letters between the first i and the last n in the word “internationalization,”) Wiki it.  Generate all such possible i18n strings for any given string. fo...

2015-07-20 11:15:32 54

原创 Google Interview - Zigzag Iterator

Suppose you have a Iterator class with has_next() and get_next() methods.Please design and implement a ZigzagIterator class as a wrapper of two iterators.For example, given two iterators:i0 = [1...

2015-07-20 10:17:07 40

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

Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. /** * Definition for a binary tree node. * struct Tr...

2015-07-20 06:00:33 51

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

Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. /** * Definition for a binary tree node. * struct Tre...

2015-07-20 05:53:02 35

原创 LeetCode 233 - Number of Digit One

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the following num...

2015-07-15 11:42:29 42

原创 HashMap

1,链表法。public class HashMap<K,V> { public static class Node<K,V> { K key; V value; Node next; public Node(K key, V value, Node<K, V> next)...

2015-07-01 05:37:36 47

原创 Google Interview - 判断点是否在凸多边形内的O(logn)解法

补充知识:向量叉积,向量P = (x1, y1); Q = (x2, y2); P×Q = (x1*y2 - x2*y1);叉积的一个非常重要性质是可以通过它的符号判断两矢量相互之间的顺逆时针关系:若 P × Q > 0 , 则P在Q的顺时针方向。若 P × Q < 0 , 则P在Q的逆时针方向。若 P × Q = 0 , 则P与Q共线,但可能同向也可能反向。叉积的方向与进行叉积的两...

2015-06-25 15:20:06 79

原创 LeetCode 82 - 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->...

2015-06-25 14:40:56 34

原创 LeetCode 83 - 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-06-25 12:28:28 39

原创 Find Islands

Given matrix MxN of 0s and 1s, return and output all groups of adjacent 1s in form of (row,col)...1s are considered adjacent if they are adjacent horizontally or vertically.1 1 0 1 0 11 1 1 1 ...

2015-06-24 11:22:07 92

原创 Longest Palindrome Subsequence

Given a sequence, find the length of the longest palindromic subsequence in it. For example, if the given sequence is “BBABCBCAB”, then the output should be 7 as “BABCBAB” is the longest palindromic ...

2015-06-23 14:07:31 79

原创 LeetCode 71 - Simplify Path

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c" Corner Cases: Did you consider the case where pa...

2015-06-22 16:20:44 37

原创 LeetCode 67 - Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". public String addBinary(String a, String b) { StringBuilder sb = new StringBuilde...

2015-06-22 15:36:51 39

原创 LeetCode - Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which...

2015-06-18 02:16:10 91

原创 LeetCode 20 - Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid b...

2015-06-16 14:41:46 40

原创 Google Interview - Valid UTF-8 Character

Write a function to validate whether the input is valid UTF-8. Input will be string or byte array, output should be true or false.UTF-8是一种变长的编码方式。它可以使用1~4个字节表示一个符号,根据不同的符号而变化字节长度。UTF-8的编码规则很简单...

2015-06-16 12:56:08 190

原创 Google Interview - Fence Painter

Write an algorithm that counts the number of ways you can paint a fence with N posts using K colors such that no more than 2 adjacent fence posts are painted with the same color.因为题目要求是不超过两个相邻...

2015-06-16 12:55:43 60

原创 Google Interview - Second Largest Number

Find the second largest number in a given array.Return 0 if the given array has no second largest number. public int secondLargest(int[] arr) { if(arr.length<2) return 0; int first =...

2015-06-15 13:19:00 63

原创 Google Interview - Flowing Water

Given a N*N matrix contains lakes, each lake is represented by an elevation. The water in each lake can flow to its neighbours which has lower or equal elevations.Suppose the left and top side of t...

2015-06-15 09:19:59 56

原创 Google Interview - Kth Smallest Element in BST

Given a binary search tree and an integer K, find K-th smallest element in BST.For example: Input: 2 / \ 1 3K = 2Output:2Note: Your solution musb be in-place without altering the nodes' valu...

2015-06-15 09:16:02 40

蘑菇街teamtalk IM全部源码

蘑菇街teamtalk服务器端以及ios,android,windows的源码整合包

2014-11-16

What Every Programmer Should Know About Memory

What Every Programmer Should Know About Memory 每个程序员都应该了解的关于内存的知识

2013-12-21

nginx web服务器 结构图

nginx 结构图,这是淘宝的一个技术牛人做的,很不错,学习。

2011-04-02

空空如也

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

TA关注的人

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