Skip to content

Instantly share code, notes, and snippets.

// Parse prefix representation into binary tree
// +12 => +
// / \
// 1 2
public class Solution {
class Node {
char c;
class Solution {
public List<List<String>> groupStrings(String[] list) {
Map<String, List<String>> m = new HashMap<>();
for (String s : list) {
String key = convert(s);
if (!m.containsKey(key)) {
m.put(key, new ArrayList<>());
}
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
public class Solution {
class Node{
int x, y;
int d;
Node(int x, int y, int d) {
this.x = x;
this.y = y;
this.d = d;
}
}
class Solution {
public int ladderLength(String beginWord, String endWord, List<String> wordList) {
Set<String> dict = new HashSet<>(wordList);
if (!dict.contains(endWord)) return 0;
Set<String> s1 = new HashSet<>();
Set<String> s2 = new HashSet<>();
Set<String> visited = new HashSet<>();
s1.add(beginWord);
s2.add(endWord);
int result = 1;
class LRUCache {
class Data {
int key;
int value;
Data(int key, int value) {
this.key = key;
this.value = value;
}
}
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
class Solution {
class Coor {
int x, y, d;
Coor(int x, int y, int d) {
this.x = x;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
class Solution {
public double[] medianSlidingWindow(int[] nums, int k) {
int len = nums.length;
double[] result = new double[len - k + 1];
Queue<Long> queue = new LinkedList<>();
class Solution {
public boolean increasingTriplet(int[] nums) {
if (nums == null || nums.length < 3) return false;
int small = Integer.MAX_VALUE, mid = Integer.MAX_VALUE;
// invariant 1: both small and mid can only go down
// invariant 2: mid will always greater than smaller
// ==> If find a number greater than both, true
for (int n : nums) {
if (n <= small) { // Find a better small
class Solution {
public int minimumTotal(List<List<Integer>> triangle) {
if (triangle == null || triangle.size() == 0) return 0;
int n = triangle.size();
int[] arr = new int[n];
arr[0] = triangle.get(0).get(0);
for (int i = 1; i < n; i++) {
List<Integer> row = triangle.get(i);