摘要: Implement int sqrt(int x).Compute and return the square root of x.二分搜索法class Solution {public: int sqrt(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if(xx){ end=mid-1; } else{ if(a+m... 阅读全文
posted @ 2013-09-12 21:01 懒猫欣 阅读(147) 评论(0) 推荐(0)
摘要: Given a number represented as an array of digits, plus one to the number.class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function bool carry=true; vector ret; ret.resize(digits.size())... 阅读全文
posted @ 2013-09-03 16:53 懒猫欣 阅读(190) 评论(0) 推荐(0)
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { string ret; while(num>999){ ret.append("M"); num-=1000; } if(num>899){ ret.ap... 阅读全文
posted @ 2013-09-03 00:24 懒猫欣 阅读(174) 评论(0) 推荐(0)
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: int romanToInt(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int lastValue=0; int value; ... 阅读全文
posted @ 2013-09-02 23:34 懒猫欣 阅读(175) 评论(0) 推荐(0)
摘要: Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are respo 阅读全文
posted @ 2013-09-02 01:25 懒猫欣 阅读(177) 评论(0) 推荐(0)
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!If the integer's last digit is 0, what should the output be? ie, cas 阅读全文
posted @ 2013-09-02 00:09 懒猫欣 阅读(161) 评论(0) 推荐(0)
摘要: warning c4251 阅读全文
posted @ 2013-08-22 11:57 懒猫欣 阅读(93) 评论(0) 推荐(0)
摘要: 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-08-22 01:05 懒猫欣 阅读(244) 评论(0) 推荐(0)
摘要: Mahout 数据转化 阅读全文
posted @ 2013-08-21 13:09 懒猫欣 阅读(135) 评论(0) 推荐(0)
摘要: Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant space so 阅读全文
posted @ 2013-08-20 20:42 懒猫欣 阅读(155) 评论(0) 推荐(0)