数据结构和算法
「已注销」
当明天成为昨天 昨天成为记忆的片段 泪水和笑脸都不是永远
展开
-
【leetcode】Palindrome Linked List
以上是AC代码 主要是方法还是双指针法 两次利用双指针法: (1),翻转前一半节点 (2),两个指针分别指向头结点和中间节点,以此比较各个节点的值 注意:总结点个数为偶数时的情况原创 2015-07-29 16:24:46 · 377 阅读 · 0 评论 -
DFS专题--【LeetCode】17. Letter Combinations of a Phone Number
Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. 中心思想:找出input digit string对应的数字的全部集合。本质就是若干for循环。 dfs类题目,可以把要输出的原创 2018-08-21 10:59:13 · 179 阅读 · 0 评论 -
【leetcode】Delete Node in a Linked List
class Solution {public: void deleteNode(ListNode* node) { if(node == NULL || node->next == NULL) return; ListNode *temp = node->next; node->val = temp->val; node->next = temp->next; free(temp); }};原创 2015-07-16 14:16:52 · 410 阅读 · 0 评论 -
【leetcode】Rotate List
class Solution { public: ListNode* rotateRight(ListNode* head, int k) { if(head == NULL) return head; ListNode *p = head; int len = 0; while(p->next){ p原创 2015-07-31 16:35:04 · 298 阅读 · 0 评论 -
【leetcode】Sort Colors
class Solution { public: void sortColors(vector& nums) { int count[3] ={0, 0, 0}; int element = 0; for(int i = 0; i < nums.size(); i++){ count[nums[i]]++;原创 2015-07-31 15:49:44 · 344 阅读 · 0 评论 -
【leetcode】Anagrams
class Solution { public: string sortedString(string &str){ int count[26]; string sortedStr = ""; for(int i = 0; i < 26; i++){ count[i] =原创 2015-07-31 20:18:23 · 510 阅读 · 0 评论 -
【leetcode】Valid Palindrome
class Solution { public: bool isCharAndNum(char &c){ if(c >= '0' && c <= '9') return true; if(c >= 'A' && c <= 'Z') { c += 32; return true; }原创 2015-07-30 18:55:37 · 362 阅读 · 0 评论 -
【leetcode】Minimum Size Subarray Sum
以上是AC代码 主要思路还是应用双指针 start 和 end 1. 固定start 移动end 找到第一个满足大于等于s的长度 2. 试着删除开始的几个元素,直到不满足s 3. 如果2没有全部之前所存储的满足s的元素, 则继续加上end指针的指向的后面的元素 4.循环2和3过程直到遍历了所有元素原创 2015-07-31 14:58:05 · 319 阅读 · 0 评论 -
【leetcode】Linked List Cycle II
class Solution { public: ListNode *detectCycle(ListNode *head) { if(head == NULL || head->next == NULL) return NULL; ListNode *fast = head; ListNode *slow = head;原创 2015-07-30 19:12:08 · 340 阅读 · 0 评论 -
【leetcode】Linked List Cycle
class Solution { public: bool hasCycle(ListNode *head) { if(head == NULL || head->next == NULL) return NULL; ListNode *fast = head; ListNode *slow = head; while(fas原创 2015-07-30 19:32:03 · 264 阅读 · 0 评论 -
DFS专题-【LeetCode】39. Combination Sum
排列组合类的题目是DFS的一个比较经典的案例。 Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to...原创 2018-08-21 12:18:07 · 180 阅读 · 0 评论