2013年9月9日

linkedlist 最难题 Insert into a Cyclic Sorted List

摘要: Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted li... 阅读全文

posted @ 2013-09-09 05:38 brave_bo 阅读(382) 评论(0) 推荐(0)

洗牌 算法

摘要: 1. for i:=1 to n do swap(a[i], a[random(1,n)]); // 凑合,但不是真正随机2. for i:=1 to n do swap(a[i], a[random(i,n)]); // 真正的随机算法其中,random(a,b)函数用于返回一个从a到b(包括a和b)的随机整数。2)的时间复杂度O(n), 空间复杂度O(1); 阅读全文

posted @ 2013-09-09 05:02 brave_bo 阅读(166) 评论(0) 推荐(0)

Maximum Depth of Binary Tree

摘要: Maximum Depth of Binary TreeMaximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Solution - RecursionThe recursion algorithm is easy to come up:Perform a DFS (depth-fi 阅读全文

posted @ 2013-09-09 03:45 brave_bo 阅读(176) 评论(0) 推荐(0)

导航