俊介三

一天更新一点,一天积累一点

导航

2013年3月11日

摘要: 实现这个函数pow(double x, int n)http://discuss.leetcode.com/questions/228/powx-n有几点要注意:1.n是整数,可以是正、负和02.x可以为03.使用divide and conquer.是的,一次for循环从0到|n|会超时,把它分成两半,时间复杂度立即减半代码入下:double pow(double x, int n) { // A trick to avoid -INT_MIN underflow if (n < 0) return 1.0 / pow(x, -(n+1)) / x; if (n == 0)... 阅读全文

posted @ 2013-03-11 20:41 俊介三在前进 阅读(166) 评论(0) 推荐(0)

摘要: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.http://discuss.leetcode.com/questio 阅读全文

posted @ 2013-03-11 20:06 俊介三在前进 阅读(144) 评论(0) 推荐(0)

摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8http://discuss.leet 阅读全文

posted @ 2013-03-11 13:09 俊介三在前进 阅读(163) 评论(0) 推荐(0)