Move Zeroes

3-13 1,269 views

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For exa...
阅读全文 0

Odd Even Linked List

5-13 1,258 views

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not ...
阅读全文 0

Remove Duplicates from Sorted Array

3-13 1,230 views

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space...
阅读全文 0

八皇后问题与回溯算法

7-11 2,610 views

八皇后问题是在8*8的棋盘上放置8枚皇后,使得棋盘中每个纵向、横向、左上至右下斜向、右上至左下斜向均只有一枚皇后。八皇后的一个可行解如图所示: ...
阅读全文 0

1000瓶药,需要多少只小白鼠试验(二)

6-17 2,391 views

1000瓶水,其中有一瓶有毒,小白鼠喝后24小时会死忙。请问最少多少只老鼠,可以在24小时测出哪瓶有毒。 答案:最少需要[log21000]=10只小白鼠 试验方法: 100...
阅读全文 0

1000瓶药有1瓶有毒,需要多少只小白鼠才能试验找出

6-17 2,311 views

1000瓶药有1瓶有毒,如果小白鼠服用有毒的药,则24小时后死亡。现在需设计一种策略,使用尽可能少的小白鼠,在24小时内找出有毒的药。 思路: 令1000瓶药的序...
阅读全文 0

一道有关飞机绕赤道飞行的面试题

6-12 2,330 views

假设赤道上有且仅有一座机场,并有若干架飞机,每架飞机的油量可保证飞半个赤道的距离。现在要求一架飞机从机场起飞,绕赤道一圈后,返回机场。在该飞机飞行...
阅读全文 0

求解二叉树的深度

6-06 2,290 views

思路: 采用递归求解,对于树tree的深度,其值为: Depth(tree) = max(Depth(tree的左子树),Depth(tree的右子树)),tree != NULL 0,tree == NULL 代码: ...
阅读全文 0

字典树

6-06 2,447 views

字典树,又名Trier树,可以用于单词的查找和统计。 字典树的示例如下图所示,其中,若根节点为第0层,则第k层节点表示字典中单词前k个字符,从根节点至树中标...
阅读全文 0

求解最长单调递增子串

6-05 2,256 views

求解最长递增子串可分为两种情况,即子串连续或非连续。 例如,对于整数串{1,3,5,1,-1,4,5,3,1,8,3,4,6,2,4,6,7,8,6,4} 其连续递增子串为{2,4,6,7,8},非连续...
阅读全文 0