/*
Following is the Node class already written for the Linked List
class Node<T> {
T data;
Node<T> next;
public Node(T data) {
this.data = data;
}
}
*/
public class Solution {
public static Node<Integer> removeDuplicates(Node<Integer> head) {
//Your code goes here
if(head == null){
return null;
}
Node<Integer> temp = head;
//Node<Integer> result = null;
while(temp.next != null) {
if(temp.data .equals(temp.next.data)){ // this is function
temp.next = temp.next.next;
} else {
temp = temp.next;
}
}
return head;
}
}
Comments
Post a Comment