摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps. For example: Given array A = [2,3,1,1,4] The minim 阅读全文
posted @ 2013-07-13 17:34 一只会思考的猪 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Implement pow(x, n).//目前写的不太好,坑比较多(n 0? x : 1.0/x; } double a = pow(x,n/2); return ans*a*a; }}; 阅读全文
posted @ 2013-07-13 16:33 一只会思考的猪 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the largest sum = 6.class Solution {public: int maxSubArray(int A[], int n) { // Start typin... 阅读全文
posted @ 2013-07-13 14:44 一只会思考的猪 阅读(93) 评论(0) 推荐(0) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A = [2,3,1,1,4], return true.A = [3,2,1,0,4], return fals 阅读全文
posted @ 2013-07-13 14:35 一只会思考的猪 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. bool compare(const Interval & ls, const Interval & rs){ return ls.start merge(vector &intervals) { // Start typing your C/C++ solution below... 阅读全文
posted @ 2013-07-13 13:34 一只会思考的猪 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.注意rotate回头的情况:{1,2,3}, 5wrong:{1,2,3}right:{2,3,1}突然想到,在白板上写程序,因为space limited,最好不要用无谓的{,},而且尽量在同一行使得代码在保证可读性的情况下 阅读全文
posted @ 2013-07-13 11:05 一只会思考的猪 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".class Solution {public: string addBinary(string a, string b) { // Start typing your C/C++ solution below // DO NOT write int main() function string ans; revers. 阅读全文
posted @ 2013-07-13 08:54 一只会思考的猪 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets. For example, If S = [1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]class Sol... 阅读全文
posted @ 2013-07-13 08:22 一只会思考的猪 阅读(161) 评论(0) 推荐(0) 编辑