leetcode
tomorrowshipy
这个作者很懒,什么都没留下…
展开
-
Longest Common Prefix
string longestCommonPrefix(vector& strs) { int n=strs.size(); if(n==0) return ""; if(n==1) return strs[0]; int i=-1; while(strs[0原创 2016-05-10 22:33:48 · 188 阅读 · 0 评论 -
链表归并排序
思路: 就是遍历两个链表,每次取最小值,temp指向该值。 ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode* temp=new ListNode(0); ListNode* head=temp; while(l1 && l2){ if(l1->valval){ temp->next=l1; l1=l原创 2016-05-12 15:22:25 · 211 阅读 · 0 评论 -
删除数组中给定的元素
题目: Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memo原创 2016-05-16 09:27:37 · 301 阅读 · 0 评论 -
Plus one
1.vector digits向最前面添加元素 : int add=2; digits.insert(digits.begin(),add); 2.删除尾元素 digits.pop_back();原创 2016-05-30 19:34:47 · 206 阅读 · 0 评论 -
全排列(含有重复元素)
题目: Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], a原创 2016-05-30 22:19:04 · 776 阅读 · 0 评论 -
判断回文串--递归实现
题目: 递归实现,判断给定字符串是否是回文串。 思路: 首先判断给定字符串首位字符是否相等,若相等,则判断去掉首尾字符后的字符串是否为回文,若不相等,则该字符串不是回文串。 代码: bool isReverseSame(const char* str ,int strlen){ if(strlen==0 || strlen==1) return true; r原创 2016-05-06 21:56:34 · 1535 阅读 · 0 评论 -
非递归求解斐波那契数列
题目:Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原创 2016-07-10 23:36:06 · 444 阅读 · 0 评论