This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
from math import log | |
def prime_fac(x): | |
"""Returning a map factor -> exponent.""" | |
c = Counter() | |
for i in xrange(2, x + 1): | |
while x % i == 0: | |
c[i] += 1 | |
x //= i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FunctionEvaluator where | |
import qualified Data.Map.Strict as M | |
evaluateFunction :: Ord a => (a -> Either b ([a], [b] -> b)) -> a -> b | |
evaluateFunction f x = snd $ memoize x M.empty | |
where | |
memoize n m = case M.lookup n m of | |
Just v -> (m, v) | |
Nothing -> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testMaliciousExpressionNFA() { | |
// NFA matching. | |
let re = REAutomata(expr: "(0|00)*1") | |
self.measureBlock { | |
XCTAssertFalse(re.test("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")) | |
} | |
} | |
func testMaliciousExpressionDFA() { | |
// DFA matching. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] == '(') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
// Divide and conquer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder