摘要: 使用快慢指针,如果有环快慢指针一定会相遇 class Solution {public: bool hasCycle(ListNode *head) { ListNode *fast, *slow; fast = slow = head; while(slow && fast) { slow = s 阅读全文
posted @ 2017-10-13 21:34 bloomingFlower 阅读(189) 评论(0) 推荐(0) 编辑
摘要: //用string的每一个元素开始往后查找直到出现重复字母为止,求出每一个结果返回最大值 时间复杂度O(n2) int lengthOfLongestSubstring(string s) { int res = 0; for(auto i = s.begin(); i != s.end(); ++ 阅读全文
posted @ 2017-10-12 14:38 bloomingFlower 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 最初的思路是返回结果 这样在循环中最后会有一个多余的链表(0)无法删除, 之后返回结果的下一个链表 解决该问题 在计算过程中 会存在连续进位的问题 比如输入[1]和[9,9,9] 最开始没有考虑到这种情况 之后使用进位数add放到while循环中解决 class Solution {public: 阅读全文
posted @ 2017-10-09 16:41 bloomingFlower 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 看背包问题 复习了下leetcode 的72 动态规划 class Solution {public: int minDistance(string word1, string word2) { int n1 = word1.length(); int n2 = word2.length(); ve 阅读全文
posted @ 2017-09-23 01:36 bloomingFlower 阅读(69) 评论(0) 推荐(0) 编辑
摘要: 用递归思想解决 f(n) = f(n - 1) * 2 + 1; python: def move(n, a, b, c): if n == 1: print('move', a, '-->', c) else: move(n - 1, a, c, b) print('move', a, '-->' 阅读全文
posted @ 2017-09-20 21:13 bloomingFlower 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 220. Contains Duplicate III 因为测试加入了int边界的数所以答案一直通不过 改成long类型就可以了 220. Contains Duplicate III 因为测试加入了int边界的数所以答案一直通不过 改成long类型就可以了 220. Contains Duplic 阅读全文
posted @ 2017-09-15 22:54 bloomingFlower 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 219. Contains Duplicate II 在这里用了multimap bug出在前置++和->的优先级顺序,也就是正文注释处,一直没加小括号 时间复杂度为O(NlogN); class Solution {public: bool containsNearbyDuplicate(vect 阅读全文
posted @ 2017-09-12 14:36 bloomingFlower 阅读(92) 评论(0) 推荐(0) 编辑
摘要: leetcode 217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value 阅读全文
posted @ 2017-09-11 15:16 bloomingFlower 阅读(100) 评论(0) 推荐(0) 编辑
摘要: leetcode 72. Edit Distance space = O(mn)解法 class Solution {public: int minDistance(string word1, string word2) { int m = word1.length(), n = word2.len 阅读全文
posted @ 2017-09-09 14:20 bloomingFlower 阅读(104) 评论(0) 推荐(0) 编辑
摘要: leetcode 168 C语言 char* convertToTitle(int n) { int count = 0, n1 = n; char alpha[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P 阅读全文
posted @ 2017-09-06 01:10 bloomingFlower 阅读(117) 评论(0) 推荐(0) 编辑