上一页 1 2 3 4 5 6 7 ··· 11 下一页
摘要: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.class Solution {public: //这个版本的快排要记住 //这个版本的Partition是 Hoare的版本 int removeElement(int A[], int n, in... 阅读全文
posted @ 2013-07-14 12:11 一只会思考的猪 阅读(219) 评论(0) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator.class Solution {public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below // DO NOT write int main() function assert(divisor); int ans = 0, step = 1, negative = ... 阅读全文
posted @ 2013-07-14 11:28 一只会思考的猪 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.class Solution {public: string add(string num1, string num2){ int i = 0, j = 0, c = 0,m = 0; string ans; while(i < num1.s... 阅读全文
posted @ 2013-07-14 00:07 一只会思考的猪 阅读(202) 评论(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.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 一只会思考的猪 阅读(200) 评论(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 一只会思考的猪 阅读(160) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 11 下一页