上一页 1 ··· 6 7 8 9 10 11 12 13 14 下一页
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val 阅读全文
posted @ 2013-01-15 12:44 西施豆腐渣 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should return length =5, and A is now[1,1,2,2,3].class Solution { public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution.. 阅读全文
posted @ 2013-01-15 07:27 西施豆腐渣 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Feb 16 '12Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length 阅读全文
posted @ 2013-01-15 05:45 西施豆腐渣 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Implement pow(x,n).class Solution { public: double pow(double x, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if( n==0) return 1; if( n==1) return x; bool sign = n>0 ? true : false; if(!si... 阅读全文
posted @ 2013-01-15 05:04 西施豆腐渣 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given a number represented as an array of digits, plus one to the number.class Solution { public: vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> rel( digits.size() ); in... 阅读全文
posted @ 2013-01-15 04:27 西施豆腐渣 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.tips: 1 remember not every dynamic programming need d[m+1][n+1] like this one.class Solution 阅读全文
posted @ 2013-01-11 08:45 西施豆腐渣 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.1. different from maximum depth. if a node only has one child, the depth will be 1 + child depth./** * Definition for binary tree * struct Tr. 阅读全文
posted @ 2013-01-11 08:25 西施豆腐渣 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ ... 阅读全文
posted @ 2013-01-11 07:55 西施豆腐渣 阅读(118) 评论(0) 推荐(0) 编辑
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.class Solution { public: void merge(int A[], int m, int B[], int n) { ... 阅读全文
posted @ 2013-01-11 07:28 西施豆腐渣 阅读(137) 评论(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]./** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : st... 阅读全文
posted @ 2013-01-11 07:05 西施豆腐渣 阅读(136) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 下一页