ByteBuffer position limit flip...
分类:
其他好文 时间:
2014-06-05 10:23:51
阅读次数:
185
【题目】
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row is greater than the last integer of the previous ...
分类:
其他好文 时间:
2014-06-05 08:28:43
阅读次数:
321
【题目】
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
【题意】
给定一个mXn的矩阵,如果其中的元素为0,则对应的行和列都用0填充。
不能申请额外的空间。
【思路】
第一行和第一列空出来标记需要置0的列和行
第一遍扫描:
扫描第一行,判断第一行是否需要清零
...
分类:
其他好文 时间:
2014-06-05 08:07:11
阅读次数:
229
【题目】
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
【题意】
有个梯子有n阶,每次只能爬1阶或者2阶,为爬到梯子顶共有多少种爬法
【思路】
依次确定跳到每一阶上的爬法数目
这其实是一...
分类:
其他好文 时间:
2014-06-05 07:16:08
阅读次数:
203
【题目】
Validate if a given string is numeric.
Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before imple...
分类:
其他好文 时间:
2014-06-04 23:45:09
阅读次数:
388
【题目】
Implement int sqrt(int x).
Compute and return the square root of x.
【题意】
实现 int sqrt(int x),计算并返回平方根。
【思路】
用牛队迭代法求解,本题可以转化为求 f(n)=n^2-x=0的解
用牛顿迭代法不断逼近真实解,假设曲线上有点(n[i],f(n[i]))
则这点出的斜率为2ni, 通过该点的直线方程为 y=2n[i](...
分类:
其他好文 时间:
2014-06-04 23:38:20
阅读次数:
325
【题目】
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad ...
分类:
其他好文 时间:
2014-06-04 22:37:46
阅读次数:
389
【题目】
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.
【题意】
给定一个已排序的链表,删除其中的重复元素
【思路】
维护两个指针prev和cur, cur指针负责扫描链表,prev指向cur的前一...
分类:
其他好文 时间:
2014-06-03 04:05:39
阅读次数:
231
【题目】
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 array.
【题意】
在“Search in Rotated Sorted Array”的基...
分类:
其他好文 时间:
2014-06-03 01:55:38
阅读次数:
173
【题目】
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->1->2->3, return 2->3.
【题意】
给定一个有序链表,删出其中重复出现的值...
分类:
其他好文 时间:
2014-05-31 21:14:11
阅读次数:
333