随笔分类 -  LeetCode Notes

摘要:采用由中心向外扩展的方法,时间复杂度为O(N^2); 注意要分成奇数长度和偶数长度; class Solution {public: string longestPalindrome(string s) { if(s.size()==0) return 0; int i=0,j=0,max=1; s 阅读全文
posted @ 2016-07-23 16:53 shawnChi 阅读(1) 评论(0) 推荐(0)
摘要:O(log(m+n))的时间复杂度,应该想到分治法的方式。 因此假设要找第(m+n)/2小的数字,则考虑在两个数组中都找第k小的数字。 考虑A[k/2]和B[k/2] 如果两个数字相等,那么这个数字就是第k小的数字。 如果两个数字不相等,则第k小的数字必然比小的大,比大的小。因此可以舍弃比小的小的和 阅读全文
posted @ 2016-07-23 13:31 shawnChi 阅读(1) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng 阅读全文
posted @ 2016-07-23 00:08 shawnChi 阅读(0) 评论(0) 推荐(0)
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single 阅读全文
posted @ 2016-07-22 23:16 shawnChi 阅读(1) 评论(0) 推荐(0)
摘要:这两个题目都是比较简单的题目,问题只在于时间复杂度上 204统计小于n的所有质数,应注意对于一个数i,只需要除到sqrt(i)即可确定是否为质数; 70应用动归方法,不要用递归方法。 204题目: Description:Count the number of prime numbers less 阅读全文
posted @ 2016-07-19 18:48 shawnChi 阅读(1) 评论(0) 推荐(0)
摘要:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. For example:Given n = 13, Return 阅读全文
posted @ 2016-07-19 18:46 shawnChi 阅读(2) 评论(0) 推荐(0)