/**
* Definition for ListNode
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
/*
* @param head: head is the head of the linked list
* @return: head of linked list
*/
public ListNode deleteDuplicates(ListNode head) {
// write your code here
if (head == null || head.next == null){
return head;
}
ListNode curr = head;
while(curr.next != null) {
int val = curr.val;
if (curr.next.val == val) {
curr.next = curr.next.next;
} else {
curr = curr.next;
}
}
return head;
}
}
Subscribe to:
Post Comments (Atom)
4. Ugly Number
1*2(t2) 2*2 3*2 (t3)1*3 2*3 3*3 (t5)1*5 2*5 3*5 1*2 2*2(t2) 3*2 1*3(t3) 2*3 3*3 (t5)1*5 2*5 3*5 Solution: public int nthUglyNumbe...
-
1*2(t2) 2*2 3*2 (t3)1*3 2*3 3*3 (t5)1*5 2*5 3*5 1*2 2*2(t2) 3*2 1*3(t3) 2*3 3*3 (t5)1*5 2*5 3*5 Solution: public int nthUglyNumbe...
-
Question: Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digit...
-
Thinking: binary Tree 和 Stringbuilder 的联合题 对Stringbuilder 和StringTokenizer的使用方法的考验 public String serialize(TreeNode root) { ...
No comments:
Post a Comment