Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
TeodorRussu wants to merge1 commit intorampatra:master
base:master
Choose a base branch
Loading
fromTeodorRussu:teo-branch
Open
Show file tree
Hide file tree
Changes fromall 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 deletionssrc/main/java/com/ctci/linkedlists/RemoveDuplicates.java
View file
Open in desktop
Original file line numberDiff line numberDiff 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 beprivate?

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

/**
* Removes duplicates in an unsorted linked list by using additional memory
* and two references.
Expand DownExpand 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();
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp