上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].class Solution { public: vector<vector<int> > permute(vector<int> &num) { // Start typing your C/C++ solution b 阅读全文
posted @ 2013-01-19 08:29 西施豆腐渣 阅读(219) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must 阅读全文
posted @ 2013-01-18 10:19 西施豆腐渣 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Given am xn matrix, if an element is 0, set its entire row and column to 0. Do it in place.uncompletedclass Solution {public: void setZeroes(vector<vector<int> > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function if( matrix.size() == 0 ) return; 阅读全文
posted @ 2013-01-18 09:36 西施豆腐渣 阅读(137) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0class Solution { p 阅读全文
posted @ 2013-01-18 07:48 西施豆腐渣 阅读(198) 评论(0) 推荐(0) 编辑
摘要: existing an array, check the longest continuous sub-array. what if the array has 5 million elements.class ArrayUtils { public: void checkContinue( int a[], n) { int max=-1; int count = 1; for(int i=1; i<n; i++) { if( a[i] == a[i-1] + 1 ) { count++; } else { max ... 阅读全文
posted @ 2013-01-17 13:40 西施豆腐渣 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Feb 16 '12Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-out nodes in the end should remain as it is.You may not alter the values in the nodes, only nodes itself may be changed.Only constant mem 阅读全文
posted @ 2013-01-17 04:38 西施豆腐渣 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 ≤m≤n≤ length of list.uncomplete./** * Definition for singly-linked list. * 阅读全文
posted @ 2013-01-16 16:07 西施豆腐渣 阅读(136) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note:Givennwill always be valid.Try to do this in one pass./ 阅读全文
posted @ 2013-01-16 09:25 西施豆腐渣 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 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: int removeElement(int A[], int n, int elem) { // Start typing your C/C++... 阅读全文
posted @ 2013-01-16 09:06 西施豆腐渣 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3./** * Definition for singly-linked list. * struct Lis 阅读全文
posted @ 2013-01-16 08:21 西施豆腐渣 阅读(142) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页