MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0083/Solution.java:13–32  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/05/10 desc :

Source from the content-addressed store, hash-verified

11 * </pre>
12 */
13public class Solution {
14 public ListNode deleteDuplicates(ListNode head) {
15 if (head == null || head.next == null) return head;
16 ListNode curr = head;
17 while (curr.next != null) {
18 if (curr.next.val == curr.val) {
19 curr.next = curr.next.next;
20 } else {
21 curr = curr.next;
22 }
23 }
24 return head;
25 }
26
27 public static void main(String[] args) {
28 Solution solution = new Solution();
29 ListNode.print(solution.deleteDuplicates(ListNode.createTestData("[1,1,2]")));
30 ListNode.print(solution.deleteDuplicates(ListNode.createTestData("[1,1,2,3,3]")));
31 }
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected