2016年4月12日

摘要: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. roman numerals: https://en.wikipedia.org/w 阅读全文

posted @ 2016-04-12 14:27 徐岩 阅读(108) 评论(0) 推荐(0)

摘要: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [1,3,2]. Solution 1: Solution 阅读全文

posted @ 2016-04-12 11:20 徐岩 阅读(99) 评论(0) 推荐(0)

摘要: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [1,2,3]. Solution 1: (递归) Sol 阅读全文

posted @ 2016-04-12 11:17 徐岩 阅读(99) 评论(0) 推荐(0)

摘要: 阅读全文

posted @ 2016-04-12 11:08 徐岩 阅读(101) 评论(0) 推荐(0)

摘要: 参考书:图论算法理论、实现及应用(北京大学出版社) 输入数据:(test.txt) 程序: 阅读全文

posted @ 2016-04-12 10:48 徐岩 阅读(1582) 评论(0) 推荐(0)

2016年4月7日

摘要: Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- w 阅读全文

posted @ 2016-04-07 22:55 徐岩 阅读(153) 评论(0) 推荐(0)

2016年4月5日

摘要: 题目描述 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 Solution 1: class Solution { public: int NumberOf1(int n) { bitset<32> bit(n); return bit.count(); } }; Solution 阅读全文

posted @ 2016-04-05 13:48 徐岩 阅读(120) 评论(0) 推荐(0)

摘要: 题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 思路:F(n) = F(n-1) + F(n-2) + F(n-3) + ... + F(n-n) 其中 F(n-k) (k = 1, 2, 3, ... n) 为第一次跳k阶, 阅读全文

posted @ 2016-04-05 13:02 徐岩 阅读(100) 评论(0) 推荐(0)

摘要: 题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减序列的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 Solution 1: class Solution { public: int 阅读全文

posted @ 2016-04-05 12:40 徐岩 阅读(96) 评论(0) 推荐(0)

摘要: 题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 Tips: 用两个栈实现一个队列的功能? 要求给出算法和思路! <分析>: 入队:将元素进栈A 出队:判断栈B是否为空,如果为空,则将栈A中所有元素pop,并push进栈B,栈B出栈; 如果不为空,栈B直 阅读全文

posted @ 2016-04-05 11:23 徐岩 阅读(108) 评论(0) 推荐(0)