pip3 install pipenv
pipenv shell
public class Solution { | |
private HashMap<Integer, UndirectedGraphNode> map = new HashMap<>(); | |
public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { | |
return clone(node); | |
} | |
private UndirectedGraphNode clone(UndirectedGraphNode node) { | |
if (node == null) return null; | |
if (map.containsKey(node.label)) { |
void zigzag(TreeNode curr, ArrayList<LinkedList<Integer>> sol, int level) { | |
if(curr == null) return; | |
if(sol.size() <= level) { | |
sol.add(new LinkedList<>()); | |
} | |
List<Integer> collection = sol.get(level); | |
if(level % 2 == 0) collection.add(curr.val); | |
else collection.add(0, curr.val); |
def tryWithResource[R <: Closeable, T](createResource: => R)(f: R => T): T = { | |
val resource = createResource | |
try f.apply(resource) finally resource.close() | |
} |
# Credit for this: Nicholas Swift | |
# as found at https://medium.com/@nicholas.w.swift/easy-a-star-pathfinding-7e6689c7f7b2 | |
from warnings import warn | |
import heapq | |
class Node: | |
""" | |
A node class for A* Pathfinding | |
""" |
jps -lm | |
jstack -l <pid> | |
jcmd <pid> Thread.print |
rows = document.querySelectorAll('tr.???'); | |
cellText = cell => cell.innerText; | |
rowText = r => Array.from(r.getElementsByTagName("td"), c => cellText(c)).join('|'); | |
csv = Array.from(rows, row => rowText(row)).join("\n"); | |
def process(kstr, vstr, n): | |
k = filter(lambda x: x != "id", kstr.split()) | |
v = vstr.split() | |
kv = list(zip(k, v)) | |
exe = filter(lambda x: x[0] == "execution", kv) | |
tot = filter(lambda x: x[0] == "total", kv) | |
times = ((float(t[1]), float(e[1])) for e,t in zip(exe, tot)) |
int lengthOfLIS(vector<int>& nums) { | |
vector<int> piles; | |
for(auto i: nums) { | |
auto it = std::lower_bound(piles.begin(), piles.end(), i); | |
if(it==piles.end()) piles.push_back(i); | |
else *it = i; | |
} | |
return piles.size(); | |
} |
import java.util.Comparator; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.PriorityBlockingQueue; | |
class PqItem { | |
public final long ts; | |
public final Runnable action; |