View prob.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View batch_clean.js
var i = 0;
var pageNumber = 5;
function clearBotFans() {
function removeFan(fanHrefElement) {
fanHrefElement.click();
const okButtons = document.querySelectorAll('a[action-type="ok"]');
if (okButtons) {
okButtons[0].click();
}
View testMaliciousExpression.swift
func testMaliciousExpressionNFA() {
// NFA matching.
let re = REAutomata(expr: "(0|00)*1")
self.measureBlock {
XCTAssertFalse(re.test("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
}
}
func testMaliciousExpressionDFA() {
// DFA matching.
View regex.cc
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
bool isMatch(string s, string p) {
int s_len = s.size(), p_len = p.size();
vector<vector<bool>> matched(p_len + 1, vector<bool>(s_len + 1, false));
View kth_bst_bad.py
# Memoize the size and iteratively get down.
# Bad because getting size requires O(n) time.
class Solution(object):
def kthSmallest(self, root, k):
"""
:type root: TreeNode
:type k: int
:rtype: int
"""
self.sz_dict = {None: 0}
View longest_paren.cc
class Solution {
public:
int longestValidParentheses(string s) {
int sz = s.size();
// Records for DP, `longest[i]` is the max number
// of pairs of brackets ending with `s[i-1]`.
vector<int> longest(sz + 1, 0);
int max_pairs = 0;
for (int i = 1; i < sz; ++i) {
if (s[i] == '(') {
View merge_k_ls.cpp
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
// Divide and conquer.
View search_range.py
class Solution(object):
def searchRange(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
left = self.lowerBound(nums, target)
if left == len(nums) or nums[left] != target:
return (-1, -1)
View btree_rightmost.py
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def rightSideView(self, root):
"""
View perfect_square.cc
// Runtime: 200ms. Typical DP.
class Solution {
public:
int numSquares(int n) {
vector<int> perfect_records(n + 1, 0);
for (int i = 1; i <= n; ++i) {
int min_to_perfect = INT_MAX;
for (int j = 1; i - j * j >= 0; ++j) {
if (perfect_records[i - j * j] < min_to_perfect) {