- 浏览: 570277 次
- 性别:
- 来自: 上海
最新评论
-
yuanhsh:
popu_12 写道Can you please explai ...
Pocket Gems专题 -
popu_12:
Can you please explain neighbor ...
Pocket Gems专题 -
月影无痕:
网站所有者也是www吗? 你这样做很不安全?详细原因见分析:正 ...
Ubuntu 11.10 安装 PHP, PHP-FPM, eAccelerator
文章列表
What is the difference between a process and a thread?
The major difference between threads and processes is:
Threads share the address space of the process that created it; processes have their own address space.
Threads have direct access to the data segment of its process; processes have t ...
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 product = 6.
public int maxProduct(int[] nums) {
int result = nums[0];
int minHere = nums[ ...
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
Note: The result may be very large, so you need to return a string instead of an integer.
public String largestNumber(int[] nu ...
Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k.
Have you met this question in a real interview?
Yes
Example
Given colors=[3, 2, 2, 1, 4],
在早期的计算机领域,限流技术(time limiting)被用作控制网络接口收发通信数据的速率。 可以用来优化性能,减少延迟和提高带宽等。现在在互联网领域,也借鉴了这个概念, 用来为服务控制请求的速率, 如果双十一的限流, 12306的抢票等。即使在细粒度的软件架构中,也有类似的概念。 比如Java线程池可以用Bounded queues保存待执行的任务, 一旦超过queue的容量, 线程池可以根据配置的策略处理此请求。
两种常用算法
令牌桶(Token Bucket)和漏桶(leaky bucket)是最常用的两种限流的算法。
Java Blocking Queue
- 博客分类:
- Java
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 empty queue is blocked until some other thread inserts an item into the queue. A thread trying to enq ...
Let’s face it. Nobody likes a slow application. It is our job to make sure our applications fulfill the functionality need completely, but at the same time delivers good user experience.
In 16 years of my experience in technical support primarily in the world of JEE, while I cannot honestly sa ...
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<Integer>> permute(int[] num) {
List<List<Integer&
There are a row of houses, each house can be painted with three colors red, blue and green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. You have to paint the houses with minimum cost. How wo ...
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
↘
c1 → c2 → c3
↗
B: b1 → b2 → b3
begin to intersect a ...
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 occurrences of it with another letter while the ordering of the letters remains unchanged. No two letters may ...
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 string contains only lowercase alphabets.
Solution:
bool ...
一个 n x n 矩阵,每个房间可能是封闭的房间,可能是警察,可能是开的房间, 封闭的房间不能过,返回一个n x n矩阵,每一个元素是最近的警察到这个房间的最短距离。 初始矩阵中-1代表封闭房间,INT_MAX代表普通房间,0代表有警察的房间。
Solution: 把警察都找出来,然后一起push到BFS的queue里面,同时搜索。复杂度可降为O(n^2)。
Starting from police and override the distance with smaller value if multiple polices can reach the same office. ...
两种最常用的 HTTP 方法是:GET 和 POST。
什么是 HTTP?
超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信。
HTTP 的工作方式是客户机与服务器之间的请求-应答协议。
web 浏览器可能是客户端,而计算机上的网络应用程序也可能作为服务器端。
举例:客户端(浏览器)向服务器提交 HTTP 请求;服务器向客户端返回响应。响应包含关于请求的状态信息以及可能被请求的内容。
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;
for(int i=0; i<32; i++) {
int v = (n >>> i) & 1;
if(v == 1) {
len++;
ma ...