摘要: Implement pow(x,n).思路:这道题的关键在于 时间。想办法让时间复杂度降低。(但有一点我没想懂,不考虑大小溢出问题么?难道因为是double的原因?待我研究下)解法很巧妙。想了好久,觉得这个解释更合理一点。n = 2k+m ----> xn = (x2)k·xm数n可以拆分成2k+m... 阅读全文
posted @ 2015-03-14 17:02 jasmine_turnsoul 阅读(149) 评论(0) 推荐(0)
摘要: 计算机中的数都是以二进制存储,位运算是直接对二进制数进行操作的运算,它的速度非常快。移位运算是其中比较常用的。1. 移位运算分为 逻辑移位 和 算术移位。逻辑移位,是不管往哪边移动,都用0来补齐。算术移位:算术左移,用0补齐。算术右移,用符号位来补齐。注意:将移位区分为逻辑移位和算术移位的原因是,不... 阅读全文
posted @ 2015-03-14 14:52 jasmine_turnsoul 阅读(1421) 评论(0) 推荐(0)
摘要: Implementint sqrt(int x).Compute and return the square root ofx.思路:binary search ,柯西不等式√abx/mid) b=mid-1; else a=mid+1; } ... 阅读全文
posted @ 2015-03-12 22:06 jasmine_turnsoul 阅读(167) 评论(0) 推荐(0)
摘要: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文
posted @ 2015-03-12 20:02 jasmine_turnsoul 阅读(113) 评论(0) 推荐(0)
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2015-03-12 19:39 jasmine_turnsoul 阅读(157) 评论(0) 推荐(0)
摘要: it's suprised me!but it is a real problem in practice.remember it , change your solid style. 阅读全文
posted @ 2015-03-12 14:56 jasmine_turnsoul 阅读(124) 评论(0) 推荐(0)
摘要: Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to... 阅读全文
posted @ 2015-03-12 14:52 jasmine_turnsoul 阅读(110) 评论(0) 推荐(0)
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文
posted @ 2015-03-12 13:16 jasmine_turnsoul 阅读(128) 评论(0) 推荐(0)
摘要: A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文
posted @ 2015-03-12 10:16 jasmine_turnsoul 阅读(132) 评论(0) 推荐(0)
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.You m... 阅读全文
posted @ 2015-03-12 10:06 jasmine_turnsoul 阅读(107) 评论(0) 推荐(0)