https://leetcode-cn.com/problems/remove-duplicate-node-lcci/
12345678910111213141516171819202122
class Solution { public ListNode removeDuplicateNodes(ListNode head) { if (head == null) { return null; } Set<Integer> set = new HashSet<>(); ListNode p = head.next; ListNode pre = head; set.add(head.val); while(p != null) { if (!set.contains(p.val)) { set.add(p.val); pre = p; p = p.next; } else { pre.next = p.next; p = p.next; } } return head; }}
fallenk
研究僧
Hangzhou, ZJU
Entradas
118
Categorias
19
Etiquetas
44
Update your browser to view this website correctly. Update my browser now
×