/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *deleteDuplicates(ListNode *head) { if(!head) return NULL; if(!head->next) return head; ListNode *dh = new ListNode(0); dh->next = head; ListNode *pre = dh; ListNode *last = head; ListNode *cur = head->next; int cn = 1; while(cur) { if(cur->val != last->val) { if(cn > 1) { while(last != cur) { pre->next = last->next; delete last; last = pre->next; } cn = 1; } else { pre = last; last = last->next; } } else { cn ++; } cur = cur->next; } if(cn>1) { while(last != cur) { pre->next = last->next; delete last; last = pre->next; } } cur = dh->next; delete dh; return cur; } };
相关推荐
LeetCode Remove Duplicates from Sorted Array解决方案
题目描述(中等难度) 给一个链表,如果一个数属于重复数字,就把这个数删除,一个都不留。 解法一 迭代 只需要两个指针,一个指针 pre 代表重复数字的前边的一个指针,另一个指针 cur 用来遍历链表。...
26.Remove_Duplicates_from_Sorted_Array删除有序数组中的重复项【LeetCode单题讲解系列
Remove Duplicates from Sorted Array 2 Remove Duplicates from Sorted Array II 3 Search in Rotated Sorted Array 4 Search in Rotated Sorted Array II 5 Median of Two Sorted Arrays 递归实现find kth 6 ...
Remove Duplicates from Sorted List II Rotate List Remove Nth Node From End of List Swap Nodes in Pairs Reverse Nodes in k-Group Copy List with Random Pointer Linked List Cycle Linked List Cycle II ...
RemoveDuplicates for version 7.1
获取从index=1及之后的数据 ${fromlist} Get Slice From List ${list} 1 # 获取从index=1~2的数据,不包括第3个 ${fromtolist} Get Slice From List ${list} 1 3 4 Remove Duplicates-去重 ⽰例: @{list} Create ...
Remove Duplicates from Sorted List II题目: | 源码:标签:单向链表难度:中等 / Medium146. LRU Cache题目: | 源码:标签:哈希表,双向链表难度:中等 / Medium212. Word-Search-II题目: | 英文站源码:./...
demonstrates the algorithm to remove duplicates in an array of integers using vectors and unique.
Remove Duplicates from Sorted Array iii. Plus One iv. Pascal's Triangle v. Merge Sorted Array vi. Sum vii. Find Minimum in Rotated Sorted Array viii. Largest Rectangle in Histogram ix. Maximal ...
删除重复排序数组运行此脚本$ node index.js 所有输入... log ( "Length = " + removeDuplicates ( nums ) ) ;console . log ( "Modified nums = [" + nums + "]" ) ;console . log ( "------------------------------
Duplicates from Sorted Array Easy #27 Remove Element Easy #35 Search Insert Position Easy #38 Count and Say Easy #53 Maximum Subarray Easy #66 Plus One Easy #70 Climbing Stairs Easy #83 Remove ...
Leetcode经典01背包 algo 1. 数据结构与算法 数组,链表,(串和序列) 堆,栈,队列 树,图 排序,搜索 贪心,回溯,动态规划 堆:一种完全二叉树,任意节点...II | | | 75 Sort Colors 计数排序 | | | 88 Merge So
II(Remove Duplicates from Sorted List II) 2018.9.27 重建二叉树(Rebuild Binary Tree) 2018.9.28 把字符串转换成整数(Convert a string to an integer) 2018.10.8 树的子结构(Substructure of the tree) ...
第一章 顺序表1.1 删除排序数组中的重复数字 Remove Duplicates from Sorted Array给定一个排序数组,在原数组中删除重复出现的
Duplicates from Sorted List 141 Easy Linked List Cycle 160 Easy Intersection of Two Linked Lists 203 Easy Remove Linked List Elements no 206 Easy Reverse Linked List 234 Easy Palindrome Linked List
Remove_duplicates.cpp
键值对文档去重,键重复部分挑出,以及值为英文时首字母大写。如果想要排序可以先把内容放到excel中排序,中间不能有多余的回车,结尾回车一个。
Duplicates from Sorted List #0118 - Pascal's Triangle #0121 - Best Time to Buy and Sell Stock #0125 - Valid Palindrome #0136 - Single Number #0167 - Two Sum - Input Array is sorted #0189 - Rotate ...
83.删除排序链表中的重复元素 (Remove Duplicates from Sorted List) 88.合并两个有序数组 (Merge Sorted Array) 100.相同的树 (Same Tree) 104.二叉树的最大深度 (Maximum Depth of Binary Tree) 118.杨辉三角 ...