We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
Bug Report for https://neetcode.io/problems/queue
Describe the bug below and include any steps to reproduce the bug or screenshots if possible.
import java.util.OptionalInt; public class Deque { private static class Node { int value; Node previous; Node next; Node(int value) { this.value = value; } } private Node head; private Node tail; public boolean isEmpty() { return head == null; } public void append(int value) { Node newTail = new Node(value); if (isEmpty()) { head = newTail; tail = newTail; return; } tail.next = newTail; newTail.previous = tail; tail = newTail; } public void appendLeft(int value) { Node newHead = new Node(value); if (isEmpty()) { head = newHead; tail = newHead; return; } head.previous = newHead; newHead.next = head; head = newHead; } public OptionalInt pop() { if (isEmpty()) { return OptionalInt.empty(); } int removedValue = tail.value; tail = tail.previous; if (tail == null) { head = null; } else { tail.next = null; } return OptionalInt.of(removedValue); } public OptionalInt popLeft() { if (isEmpty()) { return OptionalInt.empty(); } int removedValue = head.value; head = head.next; if (head == null) { tail = null; } else { head.previous = null; } return OptionalInt.of(removedValue); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug Report for https://neetcode.io/problems/queue
Describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The text was updated successfully, but these errors were encountered: