码迷,mamicode.com
首页 >  
搜索关键字:solution upgrade    ( 13024个结果)
Remove Duplicates from Sorted List
问题:将有序链表中的重复元素删除分析:由于有序,所以p结点是否重复只需要和它的前一节点比较是否相等就可以了,我们可以定义一个helper新头结点链表 将p结点与新链表的尾结点比较,若不相等则加入新链表中。class Solution{public: ListNode *deleteDup...
分类:其他好文   时间:2014-08-02 17:47:33    阅读次数:210
[leetcode]二分查找总结
Search for a Range1.最简单的想法,用最普通的二分查找,找到target,然后向左右扩张,大量的重复的target,就会出现O(n)效率。 class Solution { public int[] searchRange(int[] A, int target) { ...
分类:其他好文   时间:2014-08-02 15:12:14    阅读次数:270
LeetCode "Restore IP Addresses"
It is all about corner cases.class Solution {public: vector retv; bool isValid(string &sub) { unsigned cnt = sub.length(); if (...
分类:其他好文   时间:2014-08-02 12:39:03    阅读次数:220
Generate Parentheses leetcode java
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is....
分类:编程语言   时间:2014-08-02 12:19:33    阅读次数:255
LeetCode "Sort List"
First I implemented it by QuickSort, but got a TLE:class Solution {public: struct Pair { Pair(ListNode *pS, ListNode *pE) : pStart(pS), p...
分类:其他好文   时间:2014-08-02 05:04:32    阅读次数:233
Subsets
Given a set of distinct integers, 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 exa...
分类:其他好文   时间:2014-08-01 23:18:42    阅读次数:246
Remove Element
问题:删除数组中和elem相等的元素,并且返回新数组大小。英语不好。。。读错题了。。class Solution {public: int removeElement(int A[], int n, int elem) { int i,j; for(int i=0;...
分类:其他好文   时间:2014-08-01 23:03:22    阅读次数:223
Roman to Integer
问题:罗马数字变为整数class Solution {public: int romanToInt(string s) { char c[10][10][10]={{"0","I","II","III","IV","V","VI","VII","VIII","IX"},{"0"...
分类:其他好文   时间:2014-08-01 23:01:02    阅读次数:209
Same Tree
问题:判断两棵二叉树是否相等class Solution {public: bool isSameTree(TreeNode *p, TreeNode *q) { if(!( (p && q && p->val==q->val) || (p==NULL && q==NULL)))...
分类:其他好文   时间:2014-08-01 22:58:12    阅读次数:195
Search Insert Position
问题:一个数应该插入到有序数组的哪个位置class Solution {public: int searchInsert(int A[], int n, int target) { int i; for(i=0;i<n;i++) if(target<=A[i]) b...
分类:其他好文   时间:2014-08-01 22:57:22    阅读次数:204
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!