上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 25 下一页
摘要: 4.1Implement a function to check if a tree is balanced For the purposes of this question,a balanced tree is defned to be a tree such that no two leaf nodes difer in distancefrom the root by more than onehttp://www.cnblogs.com/graph/archive/2013/04/12/3016433.html4.2DFS4.3Given a sorted (increasing o 阅读全文
posted @ 2013-08-21 10:36 冰点猎手 阅读(221) 评论(0) 推荐(0)
摘要: 后续遍历即可,这样每次处理当前节点时,可以综合左右节点的信息进行处理。时间复杂度为O(n)PS : 经查找维基百科LCA的定义,一个节点可以称为他自己的子节点。注意:以下代码九度上第五个case没过#includeusing namespace std;struct Node{ int val; Node * left; Node * right; Node (int value){ val = value; left = NULL; right = NULL; }};Node * createTree(){ int value; cin>>value; if(value == . 阅读全文
posted @ 2013-08-20 21:09 冰点猎手 阅读(398) 评论(0) 推荐(0)
摘要: 3.1Describe how you could use a single array to implement three stacksfor stack 1, we will use [0, n/3)for stack 2, we will use [n/3, 2n/3)for stack 3, we will use [2n/3, n)const int stackSize = 300;int buffer = new int[stackSize * 3];int stackPointer[3] = {0,0,0}; //栈顶指针,指向下一可以放元素的位置bool isEmpty(in 阅读全文
posted @ 2013-08-19 20:04 冰点猎手 阅读(227) 评论(0) 推荐(0)
摘要: 2.1 Write code to remove duplicates from an unsorted linked list/* Link list node */struct node{ int data; struct node* next;};void rem_duplicate(node *head){ if(NULL == head) return ; set hash; set.insert(head->data); while(head->next){ if(hash.find(head->next->data) == has... 阅读全文
posted @ 2013-08-19 15:18 冰点猎手 阅读(294) 评论(0) 推荐(0)
摘要: 1.1Implement an algorithm to determine if a string has all unique charactersWhat if you can not use additional data structures?bool isUniqueChars(string str) { unsigned int checklittle = 0; unsigned int checklarger = 0; for(int i = 0; i = 0 ; unsigned int temp; ... 阅读全文
posted @ 2013-08-17 16:31 冰点猎手 阅读(237) 评论(0) 推荐(0)
摘要: 转自:http://studytipsandtricks.blogspot.com/2012/05/15-most-important-differences-between-c.htmlBasic Introduce:C++ is derived from C Language. It is a Superset of C.Earlier C++ was known as C with classes.In C++, the major change was the addition of classes and a mechanism for inheriting class object 阅读全文
posted @ 2013-08-16 12:54 冰点猎手 阅读(192) 评论(0) 推荐(0)
摘要: 一开始学习函数式编程语言就被告知函数式编程语言是一种“定义式”的语言,而不是一种命令式的语言,在学习haskell的函数语法时,此感觉更加强烈,haskell的函数定义倾向于一种类似C++里面的switch /case 的语义,将函数所处理的事情分类,然后定义好每个分类该如何返回。所以我的函数笔记主要就haskell函数里的几种分类情况进行讨论:condition expression语法类似于if then else ;允许嵌套,但是每个if 必须对应一个else 否则语法报错。示例如下:--单一示例: abs 函数abs :: Int -> Int abs x = if x>= 阅读全文
posted @ 2013-08-16 11:59 冰点猎手 阅读(603) 评论(0) 推荐(0)
摘要: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You may not alter the values in the nodes, only nodes itself may be changed.Only constant memory is all 阅读全文
posted @ 2013-08-15 21:27 冰点猎手 阅读(212) 评论(0) 推荐(0)
摘要: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-lea... 阅读全文
posted @ 2013-08-15 20:24 冰点猎手 阅读(192) 评论(0) 推荐(0)
摘要: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a character class Solution {public: int minDist... 阅读全文
posted @ 2013-08-15 19:04 冰点猎手 阅读(224) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 25 下一页