随笔分类 -  LeedCode

摘要:class Solution { public: double findMedianSortedArrays(vector& nums1, vector& nums2) { int m = nums1.size(), n = nums2.size(); return (findKth(nums1, nums2, (m + n + 1) / 2) + fin... 阅读全文
posted @ 2017-11-19 21:50 PirateLHX 阅读(103) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: int convert... 阅读全文
posted @ 2017-11-19 21:07 PirateLHX 阅读(91) 评论(0) 推荐(0)
摘要:C++: 阅读全文
posted @ 2017-11-10 13:47 PirateLHX 阅读(141) 评论(0) 推荐(0)
摘要:// Best Time to Buy and Sell Stock 1class Solution { public: int maxProfit(vector& prices) { if(prices.size()==0) return 0; int maxres=prices[prices.size()-1]; ... 阅读全文
posted @ 2017-10-29 16:56 PirateLHX 阅读(146) 评论(0) 推荐(0)
摘要:正常解法 以上是正常解法,但认真分析可以发现其复杂度是O(n^2),原因很简单,首先先逐个查找去掉某一个字符的字符串是不是回文序列,查找需要n次,同时字符串与reverse后字符串的比较的次数也为n次,由此可见算法复杂度是n^2,这在leetcode上运行时会出现严重的超时,故采取第二种简单的做法, 阅读全文
posted @ 2017-10-29 13:38 PirateLHX 阅读(188) 评论(4) 推荐(0)
摘要:class Solution { public: //int compare(const void * arg1, const void *arg2) //{ //return (*(int*)arg1 - *(int*)arg2); //} vector twoSum(vector& nums, int target) { vector res; vector... 阅读全文
posted @ 2017-09-23 23:37 PirateLHX 阅读(95) 评论(0) 推荐(0)