Skip to content

some code cleanup #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/main/java/com/ctci/linkedlists/RemoveDuplicates.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
public class RemoveDuplicates {

public static final String WITHOUT_DUPS = "Without dups: ";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be private?

public static final String WITH_DUPS = "\nWith dups: ";

/**
* Removes duplicates in an unsorted linked list by using additional memory
* and two references.
Expand Down Expand Up @@ -44,7 +47,7 @@ public static void main(String[] args) {
System.out.print("With dups: ");
l1.print();
removeDuplicatesFromUnsortedList(l1);
System.out.print("Without dups: ");
System.out.print(WITHOUT_DUPS);
l1.print();

Node l2 = new Node(1);
Expand All @@ -53,10 +56,10 @@ public static void main(String[] args) {
l2.next.next.next = new Node(3);
l2.next.next.next.next = new Node(4);
l2.next.next.next.next.next = new Node(5);
System.out.print("\nWith dups: ");
System.out.print(WITH_DUPS);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n is omitted.

l2.print();
removeDuplicatesFromUnsortedList(l2);
System.out.print("Without dups: ");
System.out.print(WITHOUT_DUPS);
l2.print();

Node l3 = new Node(1);
Expand All @@ -65,24 +68,25 @@ public static void main(String[] args) {
l3.next.next.next = new Node(3);
l3.next.next.next.next = new Node(4);
l3.next.next.next.next.next = new Node(5);
System.out.print("\nWith dups: ");
System.out.print(WITH_DUPS);
l3.print();
removeDuplicatesFromUnsortedList(l3);
System.out.print("Without dups: ");
System.out.print(WITHOUT_DUPS);
l3.print();

Node l4 = new Node(1);
System.out.print("\nWith dups: ");
System.out.print(WITH_DUPS);
l4.print();
removeDuplicatesFromUnsortedList(l4);
System.out.print("Without dups: ");

System.out.print(WITHOUT_DUPS);
l4.print();

Node l5 = null;
System.out.print("\nWith dups: ");
System.out.print(WITH_DUPS);
l5.print();
removeDuplicatesFromUnsortedList(l5);
System.out.print("Without dups: ");
System.out.print(WITHOUT_DUPS);
l5.print();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/ctci/stacksandqueues/StackOfPlates.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static int pop() {
}

private static Stack<Integer> getLastStack() {
if (stackList.size() == 0 || isFull(stackList.get(stackList.size() - 1))) {
if (stackList.isEmpty() || isFull(stackList.get(stackList.size() - 1))) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

stackList.add(new Stack<>());
}
return stackList.get(stackList.size() - 1);
Expand Down