Input
#+begin_src
.NET Data type | F# Declaration |
---|---|
Int | let i = 0 or let i = 0l |
Uint | let i = 1u or let i = 1ul |
Decimal | let d = 1m or let d = 1M |
Short | let c = 2s |
Long | let l = 5L |
import kotlin.math.abs | |
// https://leetcode.com/problems/target-sum/ | |
// dp function: dp[i][j] = dp[i - 1][j - nums[i]] + dp[i - 1][j + nums[i]] | |
class TargetSum { | |
fun findTargetSumWays(nums: IntArray, target: Int): Int { | |
val dp = Array(nums.size + 1) { mutableMapOf<Int, Int>().withDefault { 0 } } | |
dp[0][0] = 1 | |
for (i in 1..nums.size) { |
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1) | |
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1) | |
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1) | |
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1) | |
(1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 0) | |
(0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1) | |
(1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1) | |
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) | |
(0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) | |
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0) |
Input
#+begin_src
.NET Data type | F# Declaration |
---|---|
Int | let i = 0 or let i = 0l |
Uint | let i = 1u or let i = 1ul |
Decimal | let d = 1m or let d = 1M |
Short | let c = 2s |
Long | let l = 5L |
from __future__ import division | |
def binary_search(xs, target): | |
""" | |
type : Listof[Val] * Val -> Int | |
input : xs :: Sorted list | |
target :: Search target | |
desp : Return the index of the element in the list, -1 if the | |
element is not in the list |
class Solution(object): | |
def addTwoNumbers(self, l1, l2): | |
ll1 = self.list2naive(l1) | |
ll2 = self.list2naive(l2) | |
a = 0 if ll1 == [] else int(''.join(map(str, ll1))[::-1]) | |
b = 0 if ll2 == [] else int(''.join(map(str, ll2))[::-1]) | |
res = a + b | |
return self.naive2list(map(int, list(str(res)[::-1]))) | |
def list2naive(self, l): |
module Decorator | |
def initialize(decorated) | |
@decorated = decorated | |
end | |
def method_missing(method, *args) | |
args.empty? ? @decorated.send(method) : @decorated.send(method, args) | |
end | |
end |
from __future__ import division | |
from collections import defaultdict, deque | |
from heapq import heappush, heappop | |
from sys import stdin | |
class UnionFindSet: | |
def __init__(self, nodes): | |
self.fa = {} | |
for n in nodes: | |
self.fa[n] = n |
import Control.Applicative | |
import Control.Monad | |
import qualified Data.ByteString.Char8 as BS | |
import Data.List | |
import Data.Maybe | |
import qualified Data.Vector as V | |
data SegTree a = | |
Node { | |
val :: a |
from __future__ import division | |
class BinaryIndexTree: | |
def __init__(self, n): | |
self.sz = n | |
self.vals = [0] * (n + 1) | |
def update(self, idx, delta): | |
"add c to the value at index idx" |
import System.IO | |
import Control.Monad | |
import Text.ParserCombinators.Parsec | |
import Text.ParserCombinators.Parsec.Expr | |
import Text.ParserCombinators.Parsec.Language | |
import qualified Text.ParserCombinators.Parsec.Token as Token | |
data BExpr = BoolConst Bool | |
| Not BExpr |