Categories
LeetCode

LeetCode 844. Backspace String Compare (Java)

Source: https://leetcode.com/problems/backspace-string-compare/

Given two strings S and T, return if they are equal when both are typed into empty text editors. #means a backspace character.

Categories
LeetCode

LeetCode 341. Flatten Nested List Iterator (Java)

Source: https://leetcode.com/problems/flatten-nested-list-iterator/

Given a nested list of integers, implement an iterator to flatten it.

Each element is either an integer, or a list — whose elements may also be integers or other lists.

Categories
LeetCode

LeetCode 232. Implement Queue using Stacks (Java)

Source: https://leetcode.com/problems/implement-queue-using-stacks/

Implement the following operations of a queue using stacks.

  • push(x) — Push element x to the back of queue.
  • pop() — Removes the element from in front of queue.
  • peek() — Get the front element.
  • empty() — Return whether the queue is empty.
Categories
LeetCode

LeetCode 225. Implement Stack using Queues (Java)

Source: https://leetcode.com/problems/implement-stack-using-queues/

Implement the following operations of a stack using queues.

  • push(x) — Push element x onto stack.
  • pop() — Removes the element on top of the stack.
  • top() — Get the top element.
  • empty() — Return whether the stack is empty.
Categories
LeetCode

LeetCode 155. Min Stack (Java)

Source Url: https://leetcode-cn.com/problems/min-stack/

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

  • push(x) — Push element x onto stack.
  • pop() — Removes the element on top of the stack.
  • top() — Get the top element.
  • getMin() — Retrieve the minimum element in the stack.
Categories
LeetCode

LeetCode 71. Simplify Path (Java)

Source: https://leetcode.com/problems/simplify-path/

Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.

In a UNIX-style file system, a period . refers to the current directory. Furthermore, a double period .. moves the directory up a level. For more information, see: Absolute path vs relative path in Linux/Unix

Note that the returned canonical path must always begin with a slash /, and there must be only a single slash / between two directory names. The last directory name (if it exists) must not end with a trailing /. Also, the canonical path must be the shortest string representing the absolute path.

Categories
LeetCode

LeetCode 20. Valid Parentheses[stack] Java

Source URL: https://leetcode.com/problems/valid-parentheses/

Given a string containing just the characters '('')''{''}''['and ']', determine if the input string is valid.

An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Note that an empty string is also considered valid.