MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

DeleteNodesFromLinkedListPresentInArray.java:1–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public ListNode modifiedList(int[] nums, ListNode head) {
3 boolean set[] = new boolean[(int)1e5+1];
4 for(int num : nums){
5 set[num] = true;
6 }
7 ListNode prev = null;
8 ListNode cur = head;
9 while(cur!=null){
10 if(set[cur.val]==true){
11 if(prev == null){ //del at head
12 head = head.next;
13 cur.next = null;
14 cur = head;
15 }else{
16 prev.next = cur.next;
17 cur.next = null;
18 cur = prev.next;
19 }
20 }else{
21 prev = cur;
22 cur = cur.next;
23 }
24 }
25 return head;
26 }
27}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected