-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DeleteMiddleElement, duplicateElements, find the kth to last node…
… in a linkedlist
- Loading branch information
1 parent
757d054
commit 2a72d23
Showing
9 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.crackingCodingInterview;public class ListNode { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.crackingCodingInterview;public class Tests { | ||
} |
26 changes: 26 additions & 0 deletions
26
src/advance/crackingCodingInterview/linkedList/general/DeleteDuplicates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package advance.crackingCodingInterview.linkedList.palindromes; | ||
|
||
import advance.crackingCodingInterview.ListNode; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class DeleteDuplicates { | ||
|
||
// TC and SC is: O(n) | ||
public void deleteDup(ListNode node) { | ||
Set<Integer> set=new HashSet<>(); | ||
ListNode previousNode=null; | ||
|
||
while (node != null){ | ||
if (set.contains(node.data)){ | ||
previousNode.next = node.next; | ||
} | ||
else { | ||
set.add(node.data); | ||
previousNode = node; | ||
} | ||
node = node.next; | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/advance/crackingCodingInterview/linkedList/general/DeleteMiddle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.crackingCodingInterview.linkedList.general;public class DeleteMiddle { | ||
} |
2 changes: 2 additions & 0 deletions
2
src/advance/crackingCodingInterview/linkedList/general/DetectLoopInLinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.crackingCodingInterview.linkedList.general;public class DetectLoopInLinkedList { | ||
} |
2 changes: 2 additions & 0 deletions
2
src/advance/crackingCodingInterview/linkedList/general/KthToLast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.crackingCodingInterview.linkedList.general;public class KthToLast { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/advance/crackingCodingInterview/linkedList/palindromes/PalindromeRC.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package advance.crackingCodingInterview; | ||
// Check if the linked list is a palindrome | ||
|
||
public class Palindrome { | ||
|
||
|
||
public boolean isPalindrome(ListNode head) { | ||
return false; | ||
} | ||
|
||
static boolean isEqual(ListNode firstNode, ListNode secondNode){ | ||
while (firstNode != null && secondNode != null){ | ||
if (firstNode.data != secondNode.data){ | ||
return false; | ||
} | ||
firstNode = firstNode.next; | ||
secondNode = secondNode.next; | ||
} | ||
return firstNode == null && secondNode == null; | ||
} | ||
|
||
public ListNode reverseAndClone(ListNode node){ | ||
|
||
} | ||
|
||
|
||
} |
2 changes: 2 additions & 0 deletions
2
src/advance/crackingCodingInterview/linkedList/palindromes/PalindromeStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.crackingCodingInterview.linkedList.palindromes;public class PalindromeStack { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package advance.linkedlist;public class LFUCache { | ||
} |