-
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.
- Loading branch information
Showing
13 changed files
with
188 additions
and
205 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
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
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
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
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
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
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,59 @@ | ||
package io.dksifoua.leetcode.utils; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class ListNode { | ||
private int value; | ||
private ListNode next; | ||
|
||
public static ListNode build(int[] array) { | ||
ListNode dummy = new ListNode(0, null); | ||
|
||
ListNode current = dummy; | ||
for (int element : array) { | ||
ListNode node = new ListNode(element, null); | ||
current.setNext(node); | ||
|
||
current = current.getNext(); | ||
} | ||
|
||
return dummy.getNext(); | ||
} | ||
|
||
public int[] toArray() { | ||
List<Integer> list = new ArrayList<>(); | ||
ListNode current = this; | ||
while (current != null) { | ||
list.add(current.getValue()); | ||
current = current.getNext(); | ||
} | ||
|
||
return list.stream().mapToInt(Integer::intValue).toArray(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder result = new StringBuilder(); | ||
|
||
ListNode current = this; | ||
while (current != null) { | ||
result.append(current.getValue()); | ||
if (current.getNext() != null) { | ||
result.append(" -> "); | ||
} else { | ||
result.append(" -> null"); | ||
} | ||
current = current.getNext(); | ||
} | ||
|
||
return result.toString(); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/test/java/io/dksifoua/leetcode/linkedlistcycle/SolutionTest.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
Oops, something went wrong.