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 t To scramble the string, we may ch…
题目链接 题目要求: 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 t To scramble the string…
1. 原题(同事给的) Max Howell 参加了谷歌的面试,出题人竟然要求 Max Howell 在白板上作出解答,Max Howell 当然愤怒地拒绝了,回家以后马上在微博上跟我们分享他的吐槽: Google: % of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off. 看来在白板上作出反转二叉树的解答并不容…
2.1 给定三个整数a,b,c,实现 int median(int a, int b, int c),返回三个数的中位数,不可使用sort,要求整数操作(比较,位运算,加减乘除等)次数尽量少,并分析说明程序最坏和平均情况下使用的操作次数. 分析:中位数的意思是一个有序列中间的一个(奇数个数情况)或者中间两个的平均值(偶数个数情况) int median(int a,int b,int c) { if(a>=b) { return (b>=c)?b:((a>c)?c:a); } else…
Count and Say 思路:递归求出n - 1时的字符串,然后双指针算出每个字符的次数,拼接在结果后面 public String countAndSay(int n) { if(n == 1) return "1"; String front = countAndSay(n - 1); int i = 0; int j = 0; String res = ""; int count = 0; while(j < front.length()){ whi…
参考链接:https://docs.google.com/spreadsheet/pub?key=0Aqt--%20wSNYfuxdGxQWVFsOGdVVWxQRlNUVXZTdEpOeEE&output=html ID Question Diff Freq Data Structure Algorithms 1 Two Sum 2 5 array sort set Two Pointers 2 Add…