2013年11月5日

Gray Code

摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文

posted @ 2013-11-05 21:38 waruzhi 阅读(163) 评论(0) 推荐(0) 编辑

Balanced Binary Tree

摘要: Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1.思路:一棵树是平衡二叉树,等价于两个子树都是平衡二叉树,并且两子树的深度差不超过1。代码: 1 int max(int a, int b){ 2 if(a... 阅读全文

posted @ 2013-11-05 21:03 waruzhi 阅读(133) 评论(0) 推荐(0) 编辑

Word Ladder

摘要: Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["hot",&q 阅读全文

posted @ 2013-11-05 18:49 waruzhi 阅读(196) 评论(0) 推荐(0) 编辑

导航