3 | using namespace std;
4 |
5 | class Worker{
6 | public:
7 | virtual ~Worker(){};
8 | // 想要 delete 的时候警告 warning: delete called on 'Worker' that is abstract but has non-virtual destructor
9 | // 添加了 vitual 的析构函数后正常。
10 | // 并且只能是 virtual 的
11 | virtual void showInfo() = 0;
12 | virtual string getDeptName() = 0;
13 | int m_Id;
14 | string m_Name;
15 | int m_DeptId;
16 | };
--------------------------------------------------------------------------------
/interview-list/230812-Meituan/3.py:
--------------------------------------------------------------------------------
1 | """ 对一个矩形切成两块, 求两部分和之差的最小值
2 | 限制: n,m 1e3
3 | """
4 | n,m = map(int, input().split())
5 | arr = [list(map(int, input().split())) for _ in range(n)]
6 |
7 | def f(arr):
8 | """ 找到一个序列的最优分割 """
9 | s = sum(arr)
10 | acc = 0
11 | ans = s
12 | for i,x in enumerate(arr):
13 | acc += x
14 | ans = min(ans, abs(s-2*acc))
15 | return ans
16 |
17 | srows = [sum(r) for r in arr]
18 | scols = [sum(c) for c in zip(*arr)]
19 | print(min(f(srows), f(scols)))
--------------------------------------------------------------------------------
/python/beginning-python-3ed-master/Chapter20/listing20-3.py:
--------------------------------------------------------------------------------
1 | import sys, re
2 | from util import *
3 |
4 | print('...')
5 |
6 | title = True
7 | for block in blocks(sys.stdin):
8 | block = re.sub(r'\*(.+?)\*', r'\1', block)
9 | if title:
10 | print('')
11 | print(block)
12 | print('
')
13 | title = False
14 | else:
15 | print('')
16 | print(block)
17 | print('
')
18 |
19 | print('')
--------------------------------------------------------------------------------
/interview-list/231109-shopee/1.py:
--------------------------------------------------------------------------------
1 | """ 找出长度为k的字符串中, 元音字母的最大数量
2 | s = "tryhard", k = 4
3 | """
4 |
5 | vowels = "aeiou"
6 |
7 | s, k = input().strip().split(',')
8 | k = int(k.split('=')[1])
9 | s = s.split('=')[1].strip().strip('"')
10 | cnt = mx = 0
11 | for i in range(k):
12 | if s[i] in vowels:
13 | cnt += 1
14 | mx = cnt
15 | for i in range(k,len(s)):
16 | if s[i] in vowels:
17 | cnt += 1
18 | if s[i-k] in vowels:
19 | cnt -= 1
20 | mx = max(mx, cnt)
21 | print(mx)
22 |
23 |
--------------------------------------------------------------------------------
/interview-list/230315-optiver/1.sh:
--------------------------------------------------------------------------------
1 | 6
2 | PRICE Facebook 80
3 | PRICE Apple 120
4 | TRADE 100 Apple SELL 90 2
5 | TRADE 10 Facebook BUY 100 4
6 | WORST_TRADE Facebook
7 | WORST_TRADE Apple
8 | # 10
9 | # 100
10 |
11 | 10
12 | PRICE Google 100
13 | TRADE 1 Google BUY 100 10
14 | WORST_TRADE Google
15 | TRADE 2 Google SELL 102 5
16 | TRADE 3 Google SELL 103 5
17 | PRICE Google 98
18 | WORST_TRADE Google
19 | TRADE 4 Google BUY 101 10
20 | TRADE 5 Google BUY 100 10
21 | WORST_TRADE Google
22 | # NO BAD TRADES
23 | # 1
24 | # 4
25 |
--------------------------------------------------------------------------------
/interview-list/230422-deer-Meituan/2.py:
--------------------------------------------------------------------------------
1 | """ 检查骰子是否合法. 要求相对面之和相同, 面数为n
2 | T 100; n 1e5; 数字 1e5
3 |
4 | 思路1: #贪心
5 | 排序之后检查是否和相同
6 | """
7 | T = int(input())
8 | def f():
9 | n = int(input())
10 | if n%2: return False
11 | arr = list(map(int, input().strip().split()))
12 | arr.sort()
13 | tgt = arr[0] + arr[-1]
14 | for i in range(n//2):
15 | if arr[i] + arr[-i-1] != tgt: return False
16 | return True
17 |
18 | for _ in range(T):
19 | ret = f()
20 | print("YES" if ret else "NO")
21 |
--------------------------------------------------------------------------------
/algorithm-ds-templates/string-字符串/KMP/KMP.md:
--------------------------------------------------------------------------------
1 | ## KMP
2 |
3 | -
4 |
5 | 关键是「部分匹配表/失配函数」, 也即匹配失败之后下一个要匹配的位置.
6 |
7 | - 部分匹配表,又称为失配函数,作用是让算法无需多次匹配S中的任何字符。能够实现线性时间搜索的关键是在主串的一些字段中检查模式串的初始字段,可以确切地知道在当前位置之前的一个潜在匹配的位置。换句话说,在不错过任何潜在匹配的情况下,"预搜索"这个模式串本身并将其译成一个包含所有可能失配的位置对应可以绕过最多无效字符的列表。
8 | - 例如, 对于 aaa, 字符串的前缀函数应该是 `pi=[0,1,2]`, 定义为 s[0...i] 的 真前缀和后缀相等的最大长度 (显然 pi[0]=0)
9 | - 而其 `nxt=[-1,0,1]`, 这是为了和编程语言中数组从0开始index保持一致. 例如当要匹配第2个元素时, 若失败, 可知 s[0...2] 的前缀函数值为2
10 | - 在下面的 search函数中, 遍历的j表示当前匹配到了字符串a的多少长度
11 |
--------------------------------------------------------------------------------
/go/z-gopl/ch2/boiling/main.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | // See page 29.
5 | //!+
6 |
7 | // Boiling prints the boiling point of water.
8 | package main
9 |
10 | import "fmt"
11 |
12 | const boilingF = 212.0
13 |
14 | func main() {
15 | var f = boilingF
16 | var c = (f - 32) * 5 / 9
17 | fmt.Printf("boiling point = %g°F or %g°C\n", f, c)
18 | // Output:
19 | // boiling point = 212°F or 100°C
20 | }
21 |
22 | //!-
23 |
--------------------------------------------------------------------------------
/go/z-gopl/ch7/tempflag/tempflag.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | // See page 181.
5 |
6 | // Tempflag prints the value of its -temp (temperature) flag.
7 | package main
8 |
9 | import (
10 | "flag"
11 | "fmt"
12 |
13 | "gopl.io/ch7/tempconv"
14 | )
15 |
16 | //!+
17 | var temp = tempconv.CelsiusFlag("temp", 20.0, "the temperature")
18 |
19 | func main() {
20 | flag.Parse()
21 | fmt.Println(*temp)
22 | }
23 |
24 | //!-
25 |
--------------------------------------------------------------------------------
/cpp/cpp-hackerrank/basic/io-scanf-printf.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | 主要参见 https://www.hackerrank.com/domains/cpp
3 | */
4 |
5 | #include
6 | #include
7 | // #include
8 | using namespace std;
9 |
10 | /*
11 | 3 12345678912345 a 334.23 14049.30493
12 | */
13 | int main() {
14 | // Complete the code.
15 | int a;
16 | long b;
17 | char c;
18 | float d;
19 | double e;
20 | scanf("%d %ld %c %f %lf", &a, &b, &c, &d, &e);
21 | printf("%d\n%ld\n%c\n%f\n%lf", a,b,c,d,e);
22 | return 0;
23 | }
--------------------------------------------------------------------------------
/js/node/http/urls.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var url = require('url');
4 |
5 | // parse url:
6 | console.log(url.parse('http://user:pass@host.com:8080/path/to/file?query=string#hash'));
7 |
8 | // parse incomplete url:
9 | console.log(url.parse('/static/js/jquery.js?name=Hello%20world'));
10 |
11 | // construct a url:
12 | console.log(url.format({
13 | protocol: 'http',
14 | hostname: 'localhost',
15 | pathname: '/static/js',
16 | query: {
17 | name: 'Nodejs',
18 | version: 'v 1.0'
19 | }
20 | }));
21 |
--------------------------------------------------------------------------------
/interview-list/misc-interview/2.py:
--------------------------------------------------------------------------------
1 | """ 二叉树的非递归后序遍历
2 |
3 | """
4 |
5 | class Node:
6 | def __init__(self) -> None:
7 | self.val = None
8 | self.left = None
9 | self.right = None
10 |
11 | def dfs(node):
12 | if not node:
13 | return
14 | stack = []
15 | stack.append(node)
16 | while stack:
17 | node = stack.pop()
18 | print(node.val)
19 | if node.left:
20 | stack.append(node.left)
21 | if node.right:
22 | stack.append(node.right)
23 |
--------------------------------------------------------------------------------
/interview-list/misc-interview/230802.py:
--------------------------------------------------------------------------------
1 | """
2 | 定义操作A为合并相邻的重复元素, 分数为所得到的数组长度. 需要将一个长度为n的数组切分为k块, 问可得的最大分数之和.
3 | 限制: n 1e5
4 | 思路1: #贪心 注意到, 一个切分操作最多增加整体分数值1
5 | 因此, 记整体的分数为a, 统计最多容许进行切分的个数即可
6 |
7 | 8 3
8 | 1 1 1 2 2 3 3 1
9 | # 6
10 | 1 4
11 | 1 1 1 1 1 1 1 1
12 | # 3
13 | """
14 |
15 | n,k = map(int, input().split())
16 | arr = list(map(int, input().split()))
17 |
18 | a = b = 0
19 | pre = -1
20 | for x in arr:
21 | if x!=pre:
22 | a += 1
23 | else:
24 | b += 1
25 | pre = x
26 |
27 | print(a + min(b, k-1))
--------------------------------------------------------------------------------
/js/underscore/underscore.js:
--------------------------------------------------------------------------------
1 | function testMap() {
2 | var obj = {
3 | name: "bob",
4 | school: "No.1 middle school",
5 | address: "xueyuan road",
6 | };
7 | // 注意, map 返回的仅仅是 value 的 Array
8 | var upper = _.map(obj, function (value, key) {
9 | return key + ": " + value.toUpperCase();
10 | });
11 | console.log(upper);
12 |
13 | upper = _.mapObject(obj, function (value, key) {
14 | return value.toUpperCase();
15 | });
16 | console.log(upper);
17 | }
18 |
19 | testMap();
20 |
--------------------------------------------------------------------------------
/python/beginning-python-3ed-master/Chapter15/listing15-7.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import cgi
4 | form = cgi.FieldStorage()
5 |
6 | name = form.getvalue('name', 'world')
7 |
8 | print("""Content-type: text/html
9 |
10 |
11 |
12 | Greeting Page
13 |
14 |
15 | Hello, %s!
16 |
17 |
18 |
22 |
23 |
24 | """.format(name))
--------------------------------------------------------------------------------
/interview-list/230321-ant-deer/2.py:
--------------------------------------------------------------------------------
1 |
2 | """
3 | 对于一个序列, 计算 (i,j,k) 组, 满足 2j = i+k
4 | 限制: n 2e3
5 | 思路1: 两两匹配枚举
6 | """
7 |
8 | from collections import Counter
9 | n = int(input())
10 | arr = list(map(int, input().split()))
11 | cnt = Counter(arr)
12 | ans = 0
13 | # 枚举中间的那个均值
14 | for i,c1 in cnt.items():
15 | # 枚举剩余的两个数字, 计数
16 | # i = j=k
17 | if c1>=3: ans += c1*(c1-1)*(c1-2)
18 | # 不相等的情况
19 | for j,c2 in cnt.items():
20 | if i==j: continue
21 | ans += c1*c2*cnt[2*j-i]
22 | print(ans)
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/interview-list/230729-Shein-NLP/1.py:
--------------------------------------------------------------------------------
1 | """ 给定两个递增序列, 从两个数组中分别取一个数字相加, 问得到最大的k个数字
2 | 限制: k <= 2n. 要求复杂度 O(klogk)
3 | """
4 | n,k = map(int, input().split())
5 | a = list(map(int, input().split()))
6 | b = list(map(int, input().split()))
7 |
8 | import heapq
9 | ans = []
10 | h = []
11 | for aa in a:
12 | h.append((-aa-b[-1], aa, n-1))
13 | heapq.heapify(h)
14 | for _ in range(k):
15 | mx, aa, i = heapq.heappop(h)
16 | ans.append(-mx)
17 | if i > 0:
18 | heapq.heappush(h, (-aa-b[i-1], aa, i-1))
19 | print(" ".join(map(str, ans)))
--------------------------------------------------------------------------------
/js/node/fs/use_stat.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const fs = require('fs');
4 |
5 | fs.stat('sample.txt', function (err, stat) {
6 | if (err) {
7 | console.log(err);
8 | } else {
9 | console.log('isFile: ' + stat.isFile());
10 | console.log('isDirectory: ' + stat.isDirectory());
11 | if (stat.isFile()) {
12 | console.log('size: ' + stat.size);
13 | console.log('birth time: ' + stat.birthtime);
14 | console.log('modified time: ' + stat.mtime);
15 | }
16 | }
17 | });
18 |
--------------------------------------------------------------------------------
/LC-contest/luogu/1-入门/1035/1035.py:
--------------------------------------------------------------------------------
1 | """ P1035 [NOIP2002 普及组] 级数求和 #入门
2 | 对于调和级数 S(n) = 1 + 1/2 + 1/3 + ... + 1/n. 现给定一个整数k, 问 S(n) > k 的最小n.
3 | 限制: k<=15
4 | 思路1: #暴力 模拟
5 | 复杂度:
6 | 若按照naive的缩放, 对于因子 1/2, 不考虑首位的1, 可以通过 1,2,4,8.. 个元素之和得到, 这样的话时间复杂度约为 O(2^(2k)) 似乎不够
7 | 但实际上在 k=15 的时候答案在 1e7 级别
8 | 实际上, 按照欧拉推导过程, 调和级数之和的增长率为 e, 这样是符合要求的. 见 [here](https://www.luogu.com.cn/blog/Loner-Knowledge/Solutions-P1035)
9 | """
10 |
11 | k = int(input())
12 | s = 0; i = 1
13 | while s <= k:
14 | s += 1/i
15 | i += 1
16 | print(i-1)
--------------------------------------------------------------------------------
/LC-contest/luogu/1-入门/1304/1304.py:
--------------------------------------------------------------------------------
1 | """ P1304 哥德巴赫猜想
2 | 哥德巴赫猜想:任一大于 2 的偶数都可写成两个质数之和. 现在给定一个整数n, 写出 4,6,...n 的第一个因子最小的分解式 (例如10=3+7 而非 5+5).
3 | """
4 | n = int(input())
5 | primes = set([2])
6 | for i in range(3, n):
7 | flag = True
8 | for p in primes:
9 | if i%p == 0:
10 | flag = False
11 | break
12 | if flag:
13 | primes.add(i)
14 | ps = sorted(primes)
15 | for i in range(4, n+1, 2):
16 | for p in ps:
17 | if i-p in primes:
18 | print(f"{i}={p}+{i-p}")
19 | break
20 |
--------------------------------------------------------------------------------
/go/z-gopl/ch11/word1/word.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | // See page 303.
5 | //!+
6 |
7 | // Package word provides utilities for word games.
8 | package word
9 |
10 | // IsPalindrome reports whether s reads the same forward and backward.
11 | // (Our first attempt.)
12 | func IsPalindrome(s string) bool {
13 | for i := range s {
14 | if s[i] != s[len(s)-1-i] {
15 | return false
16 | }
17 | }
18 | return true
19 | }
20 |
21 | //!-
22 |
--------------------------------------------------------------------------------
/go/z-gopl/ch9/memo2/memo_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | package memo_test
5 |
6 | import (
7 | "testing"
8 |
9 | "gopl.io/ch9/memo2"
10 | "gopl.io/ch9/memotest"
11 | )
12 |
13 | var httpGetBody = memotest.HTTPGetBody
14 |
15 | func Test(t *testing.T) {
16 | m := memo.New(httpGetBody)
17 | memotest.Sequential(t, m)
18 | }
19 |
20 | func TestConcurrent(t *testing.T) {
21 | m := memo.New(httpGetBody)
22 | memotest.Concurrent(t, m)
23 | }
24 |
--------------------------------------------------------------------------------
/go/z-gopl/ch9/memo3/memo_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | package memo_test
5 |
6 | import (
7 | "testing"
8 |
9 | "gopl.io/ch9/memo3"
10 | "gopl.io/ch9/memotest"
11 | )
12 |
13 | var httpGetBody = memotest.HTTPGetBody
14 |
15 | func Test(t *testing.T) {
16 | m := memo.New(httpGetBody)
17 | memotest.Sequential(t, m)
18 | }
19 |
20 | func TestConcurrent(t *testing.T) {
21 | m := memo.New(httpGetBody)
22 | memotest.Concurrent(t, m)
23 | }
24 |
--------------------------------------------------------------------------------
/go/z-gopl/ch9/memo4/memo_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | package memo_test
5 |
6 | import (
7 | "testing"
8 |
9 | "gopl.io/ch9/memo4"
10 | "gopl.io/ch9/memotest"
11 | )
12 |
13 | var httpGetBody = memotest.HTTPGetBody
14 |
15 | func Test(t *testing.T) {
16 | m := memo.New(httpGetBody)
17 | memotest.Sequential(t, m)
18 | }
19 |
20 | func TestConcurrent(t *testing.T) {
21 | m := memo.New(httpGetBody)
22 | memotest.Concurrent(t, m)
23 | }
24 |
--------------------------------------------------------------------------------
/js/node/web/test/hello-test/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mocha-test",
3 | "version": "1.0.0",
4 | "description": "Mocha simple test",
5 | "main": "hello.js",
6 | "scripts": {
7 | "test": "mocha"
8 | },
9 | "keywords": [
10 | "mocha",
11 | "test"
12 | ],
13 | "author": "Michael Liao",
14 | "license": "Apache-2.0",
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/michaelliao/learn-javascript.git"
18 | },
19 | "dependencies": {},
20 | "devDependencies": {
21 | "mocha": "3.0.2"
22 | }
23 | }
--------------------------------------------------------------------------------
/interview-list/240317-小红书-test/2.py:
--------------------------------------------------------------------------------
1 | """
2 | #P1710. 2024.3.17-小红书-第二题-推荐算法
3 | https://codefun2000.com/p/P1710
4 | """
5 | from collections import defaultdict
6 | n,q = map(int, input().split())
7 | keywords = set(input().split())
8 | num2list = defaultdict(list)
9 | for _ in range(n):
10 | name, _ = input().split()
11 | keys = set(input().split())
12 | num_inter = len(keywords & keys)
13 | num2list[num_inter].append(name)
14 | for num in sorted(num2list.keys(), reverse=True):
15 | for name in num2list[num]:
16 | print(name)
17 |
18 |
--------------------------------------------------------------------------------
/java/src/basic/ExecFloat.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 |
4 | public class ExecFloat {
5 |
6 | public static void main(String[] args) {
7 | // x*x + 3*x - 4 = 0
8 | double a = 1.0;
9 | double b = 3.0;
10 | double c = -4.0;
11 | // 求平方根可用 Math.sqrt():
12 | // double x = Math.sqrt(2)); // ==> 1.414
13 | double rr = Math.sqrt(b*b - 4*a*c);
14 | double r1 = (-b + rr) / (2*a);
15 | double r2 = (-b - rr) / (2*a);
16 | System.out.println(r1 + ", " + r2);
17 | System.out.println(r1 == 1 && r2 == -4 ? "测试通过" : "测试失败");
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/LC-contest/codeforce/#804 (Div. 2)/a.py:
--------------------------------------------------------------------------------
1 | """ A. The Third Three Number Problem
2 | 给定一个数字n, 要求找到三个非负数a,b,c, 是的` a^b+b^c+c^a == n`
3 | 思路1: #归纳
4 | 根据给的例子, 可以发现, 在每一bit中, 若三个数字中该比特为1的次数出现了0/3次则对结构不影响, 若出现了1/2次则在结果中计数两次.
5 | 因此, 可知n必然为偶数, 并且是a,b,c三个数中, 所谓出现1/2次的比特位所代表数字的2倍.
6 | 现在要求找出一种 a,b,c, 只需要将 n//2 的比特位分配到三个数字上即可, 一种简单的方法就是 `(n//2, 0, 0)`
7 |
8 | https://codeforces.com/contest/1699/problem/A
9 | """
10 | t = int(input())
11 | for i in range(t):
12 | n = int(input())
13 | if n&1:
14 | print(-1); continue
15 | print(n//2, 0, 0)
16 |
--------------------------------------------------------------------------------
/js/node/web/koa/url2-koa/app.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 |
3 | const bodyParser = require('koa-bodyparser');
4 |
5 | const controller = require('./controller');
6 |
7 | const app = new Koa();
8 |
9 | // log request URL:
10 | app.use(async (ctx, next) => {
11 | console.log(`Process ${ctx.request.method} ${ctx.request.url}...`);
12 | await next();
13 | });
14 |
15 | // parse request body:
16 | app.use(bodyParser());
17 |
18 | // add controllers:
19 | app.use(controller());
20 |
21 | app.listen(3000);
22 | console.log('app started at port 3000...');
23 |
--------------------------------------------------------------------------------
/js/node/web/rest/rest-hello/app.js:
--------------------------------------------------------------------------------
1 | const Koa = require('koa');
2 |
3 | const bodyParser = require('koa-bodyparser');
4 |
5 | const controller = require('./controller');
6 |
7 | const app = new Koa();
8 |
9 | // log request URL:
10 | app.use(async (ctx, next) => {
11 | console.log(`Process ${ctx.request.method} ${ctx.request.url}...`);
12 | await next();
13 | });
14 |
15 | // parse request body:
16 | app.use(bodyParser());
17 |
18 | // add controller:
19 | app.use(controller());
20 |
21 | app.listen(3000);
22 | console.log('app started at port 3000...');
23 |
--------------------------------------------------------------------------------
/interview-list/230428-Merchants-招商银行/3.py:
--------------------------------------------------------------------------------
1 | """
2 | 对于一个数字, 统计满足条件的数组: h!=t, 同时 (h..t) 之间的元素都不等于h/t
3 | 限制: N 2e5; 数组的元素范围 N
4 |
5 | 7
6 | 1 2 3 4 3 2 5
7 | # 13
8 | # 注意区间 (1,7) 也满足!
9 | 4
10 | 1 2 1 2
11 | # 3
12 |
13 | 思路0: 不会做, 下面写了个 O(n^2) 的实现.
14 |
15 | """
16 | n = int(input())
17 | arr = list(map(int, input().split()))
18 | ans = 0
19 | for i,x in enumerate(arr):
20 | s = set()
21 | for j in range(i+1,n):
22 | y = arr[j]
23 | if y==x: break
24 | if y in s: continue
25 | s.add(y)
26 | ans += 1
27 | print(ans)
28 |
29 |
--------------------------------------------------------------------------------
/cpp/cpp-hackerrank/basic/2-basic-datatype.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Int ("%d"): 32 Bit integer
3 | Long ("%ld"): 64 bit integer
4 | Char ("%c"): Character type
5 | Float ("%f"): 32 bit real value
6 | Double ("%lf"): 64 bit real value
7 | */
8 |
9 | #include
10 | #include
11 | using namespace std;
12 |
13 | int main() {
14 | // Complete the code.
15 | int a;
16 | long b;
17 | char c;
18 | float d;
19 | double e;
20 | scanf("%d %ld %c %f %lf", &a, &b, &c, &d, &e);
21 | printf("%d\n%ld\n%c\n%f\n%lf", a,b,c,d,e);
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/js/node/os/get_os_info.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const os = require('os');
4 |
5 | console.log('CPU: ' + JSON.stringify(os.cpus()));
6 |
7 | console.log('Network: ' + JSON.stringify(os.networkInterfaces()));
8 |
9 | console.log('Total memory: ' + os.totalmem());
10 |
11 | console.log('Free memory: ' + os.freemem());
12 |
13 | console.log('Hostname: ' + os.hostname());
14 |
15 | console.log('Platform: ' + os.platform());
16 |
17 | console.log('Temp dir: ' + os.tmpdir());
18 |
19 | console.log('OS type: ' + os.type());
20 |
21 | console.log('Uptime: ' + os.uptime());
22 |
--------------------------------------------------------------------------------
/python/LA/07.py:
--------------------------------------------------------------------------------
1 |
2 | """ 基向量变换矩阵
3 | 在线性代数中,同一个向量可以在不同的基下表示。给定 R3 空间中两组基向量 B 和 C,实现一个函数来计算从基 C 到基B 的变换矩阵 P。
4 | [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
5 | [[1, 1, 0], [0, 1, 1], [1, 0, 1]]
6 | >
7 | [[0.5, -0.5, 0.5], [0.5, 0.5, -0.5], [-0.5, 0.5, 0.5]]
8 | """
9 | import numpy as np
10 |
11 | def transform_basis(B: np.ndarray, C: np.ndarray) -> list:
12 | m = np.linalg.inv(C) @ B
13 | return m.tolist()
14 |
15 |
16 | if __name__ == "__main__":
17 | B = np.array(eval(input()))
18 | C = np.array(eval(input()))
19 | print(transform_basis(B, C))
20 |
21 |
22 |
--------------------------------------------------------------------------------
/cpp/learn-cpp-heima/468-rect-inderitance.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | class Animal{
5 | public:
6 | int m_Age;
7 | };
8 |
9 | //继承前加virtual关键字后,变为虚继承
10 | //此时公共的父类Animal称为虚基类
11 | class Sheep: public virtual Animal{};
12 | class Tuo: virtual public Animal{};
13 |
14 | class SheepTuo: public Sheep, public Tuo{};
15 |
16 |
17 | int main() {
18 | SheepTuo st;
19 | st.Sheep::m_Age = 25;
20 | st.Tuo::m_Age = 28;
21 | cout << sizeof(st) << endl;
22 | cout << st.Sheep::m_Age << st.Tuo::Tuo::m_Age << st.m_Age << endl;
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/interview-list/others/Newcoder-Huawei/进制转换.py:
--------------------------------------------------------------------------------
1 | """
2 | 题目描述
3 | 写出一个程序,接受一个十六进制的数,输出该数值的十进制表示。
4 |
5 | 输入描述:
6 | 输入一个十六进制的数值字符串。注意:一个用例会同时有多组输入数据,请参考帖子https://www.nowcoder.com/discuss/276处理多组输入的问题。
7 |
8 | 输出描述:
9 | 输出该数值的十进制字符串。不同组的测试用例用\n隔开。
10 |
11 | 示例1
12 | 输入
13 | 复制
14 | 0xA
15 | 0xAA
16 | 输出
17 | 复制
18 | 10
19 | 170
20 | """
21 |
22 | import sys
23 |
24 | hex2int = {c:i for i, c in enumerate('0123456789ABCDEF')}
25 |
26 | for line in sys.stdin:
27 | line = line[2:].strip()
28 | num = 0
29 | for c in line:
30 | num = 16*num + hex2int[c]
31 | print(num)
--------------------------------------------------------------------------------
/js/node/web/log/winston/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "logger",
3 | "version": "1.0.0",
4 | "description": "Log example",
5 | "main": "app.js",
6 | "scripts": {
7 | "start": "node app.js"
8 | },
9 | "keywords": [
10 | "log",
11 | "winston"
12 | ],
13 | "author": "Michael Liao",
14 | "license": "Apache-2.0",
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/michaelliao/learn-javascript.git"
18 | },
19 | "dependencies": {
20 | "winston": "2.3.1"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/LC-go/structures/Queue_test.go:
--------------------------------------------------------------------------------
1 | package structures
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/stretchr/testify/assert"
7 | )
8 |
9 | func Test_Queue(t *testing.T) {
10 | ast := assert.New(t)
11 |
12 | q := NewQueue()
13 | ast.True(q.IsEmpty(), "检查新建的 q 是否为空")
14 |
15 | start, end := 0, 100
16 |
17 | for i := start; i < end; i++ {
18 | q.Push(i)
19 | ast.Equal(i-start+1, q.Len(), "Push 后检查 q 的长度。")
20 | }
21 |
22 | for i := start; i < end; i++ {
23 | ast.Equal(i, q.Pop(), "从 q 中 pop 出数来。")
24 | }
25 |
26 | ast.True(q.IsEmpty(), "检查 Pop 完毕后的 q 是否为空")
27 | }
28 |
--------------------------------------------------------------------------------
/go/z-gopl/ch4/treesort/sort_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | package treesort_test
5 |
6 | import (
7 | "fmt"
8 | "math/rand"
9 | "sort"
10 | "testing"
11 |
12 | "gopl.io/ch4/treesort"
13 | )
14 |
15 | func TestSort(t *testing.T) {
16 | data := make([]int, 50)
17 | for i := range data {
18 | data[i] = rand.Int() % 50
19 | }
20 | treesort.Sort(data)
21 | fmt.Println(data)
22 | if !sort.IntsAreSorted(data) {
23 | t.Errorf("not sorted: %v", data)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/go/z-gopl/ch7/sleep/sleep.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | // See page 179.
5 |
6 | // The sleep program sleeps for a specified period of time.
7 | package main
8 |
9 | import (
10 | "flag"
11 | "fmt"
12 | "time"
13 | )
14 |
15 | //!+sleep
16 | var period = flag.Duration("period", 1*time.Second, "sleep period")
17 |
18 | func main() {
19 | flag.Parse()
20 | fmt.Printf("Sleeping for %v...", *period)
21 | time.Sleep(*period)
22 | fmt.Println()
23 | }
24 |
25 | //!-sleep
26 |
--------------------------------------------------------------------------------
/interview-list/230909-美团/4.py:
--------------------------------------------------------------------------------
1 | """ TODO: 复杂度不够
2 | 定义数组的权重为, 任意两个数的异或之和.
3 | 所有 连续子数组 的权值和是多少. 答案取模.
4 | 限制: n 1e5
5 | 思路0: 暴力, O(n^2)
6 | 考虑 i,j 两个位置的元素, 它们会被计算多少次异或值?
7 | 此时, 子数组一定包含 [i...j] 这个区间, 再遍历所有, 一共计数 (i+1)*(n-j) 次
8 | """
9 | n = int(input())
10 | arr = list(map(int, input().split()))
11 | mod = 10**9+7
12 |
13 | def brust(arr):
14 | n = len(arr)
15 | ans = 0
16 | for i in range(len(arr)):
17 | for j in range(i+1, len(arr)):
18 | ans += (arr[i]^arr[j]) * (i+1) * (n-j)
19 | ans %= mod
20 | return ans
21 | print(brust(arr))
--------------------------------------------------------------------------------
/LC-go/structures/Stack_test.go:
--------------------------------------------------------------------------------
1 | package structures
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/stretchr/testify/assert"
7 | )
8 |
9 | func Test_Stack(t *testing.T) {
10 | ast := assert.New(t)
11 |
12 | s := NewStack()
13 | ast.True(s.IsEmpty(), "检查新建的 s 是否为空")
14 |
15 | start, end := 0, 100
16 |
17 | for i := start; i < end; i++ {
18 | s.Push(i)
19 | ast.Equal(i-start+1, s.Len(), "Push 后检查 q 的长度。")
20 | }
21 |
22 | for i := end - 1; i >= start; i-- {
23 | ast.Equal(i, s.Pop(), "从 s 中 pop 出数来。")
24 | }
25 |
26 | ast.True(s.IsEmpty(), "检查 Pop 完毕后的 s 是否为空")
27 | }
28 |
--------------------------------------------------------------------------------
/java/Maven_/maven-hello/src/main/java/com/itranswarp/learnjava/Main.java:
--------------------------------------------------------------------------------
1 | package com.itranswarp.learnjava;
2 |
3 | import org.slf4j.LoggerFactory;
4 |
5 | /**
6 | * App entry for Maven project.
7 | *
8 | * @author liaoxuefeng
9 | */
10 | public class Main {
11 |
12 | public static void main(String[] args) throws Exception {
13 | var logger = LoggerFactory.getLogger(Main.class);
14 | logger.info("start application...");
15 | for (int i = 1; i <= 10; i++) {
16 | Thread.sleep(100);
17 | logger.warn("begin task {}...", i);
18 | }
19 | logger.info("done.");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/java/Maven_/maven-plugin/src/main/java/com/itranswarp/learnjava/Main.java:
--------------------------------------------------------------------------------
1 | package com.itranswarp.learnjava;
2 |
3 | import org.slf4j.LoggerFactory;
4 |
5 | /**
6 | * App entry for Maven project.
7 | *
8 | * @author liaoxuefeng
9 | */
10 | public class Main {
11 |
12 | public static void main(String[] args) throws Exception {
13 | var logger = LoggerFactory.getLogger(Main.class);
14 | logger.info("start application...");
15 | for (int i = 1; i <= 10; i++) {
16 | Thread.sleep(100);
17 | logger.warn("begin task {}...", i);
18 | }
19 | logger.info("done.");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/js/node/web/ws/hello-ws/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hello-ws",
3 | "version": "1.0.0",
4 | "description": "Hello WebSocket example",
5 | "main": "app.js",
6 | "scripts": {
7 | "start": "node app.js"
8 | },
9 | "keywords": [
10 | "ws",
11 | "websocket"
12 | ],
13 | "author": "Michael Liao",
14 | "license": "Apache-2.0",
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/michaelliao/learn-javascript.git"
18 | },
19 | "dependencies": {
20 | "ws": "1.1.1"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/python/beginning-python-3ed-master/Chapter14/listing14-8.py:
--------------------------------------------------------------------------------
1 | from twisted.internet import reactor
2 | from twisted.internet.protocol import Protocol, Factory
3 |
4 | class SimpleLogger(Protocol):
5 |
6 | def connectionMade(self):
7 | print 'Got connection from', self.transport.client
8 |
9 | def connectionLost(self, reason):
10 | print self.transport.client, 'disconnected'
11 |
12 | def dataReceived(self, data):
13 | print data
14 |
15 | factory = Factory()
16 | factory.protocol = SimpleLogger
17 |
18 | reactor.listenTCP(1234, factory)
19 | reactor.run()
--------------------------------------------------------------------------------
/LC-contest/luogu/5-提高+~省选-/P4513 小白逛公园/P4513_2.out:
--------------------------------------------------------------------------------
1 | 1252
2 | 1252
3 | 798
4 | 1641
5 | 1547
6 | 2062
7 | 2880
8 | 1967
9 | 3628
10 | 1533
11 | 650
12 | 4955
13 | 1742
14 | 1701
15 | 5776
16 | 1349
17 | 456
18 | 741
19 | 5470
20 | 5805
21 | 5425
22 | 5859
23 | 1243
24 | 5425
25 | 5425
26 | 5642
27 | 3724
28 | -302
29 | 3162
30 | 3103
31 | 2392
32 | 2706
33 | 4343
34 | 1689
35 | 2897
36 | 2598
37 | 5873
38 | 3789
39 | 1478
40 | 1653
41 | -474
42 | 5905
43 | -834
44 | -908
45 | -702
46 | -994
47 | -883
48 | -834
49 | -702
50 | -702
51 | -883
52 | -702
53 | -702
54 | -702
55 | -702
56 | -702
57 | -702
58 |
--------------------------------------------------------------------------------
/LC-go/structures/NestedInterger_test.go:
--------------------------------------------------------------------------------
1 | package structures
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/stretchr/testify/assert"
7 | )
8 |
9 | func Test_NestedInteger(t *testing.T) {
10 | ast := assert.New(t)
11 |
12 | n := NestedInteger{}
13 |
14 | ast.True(n.IsInteger())
15 |
16 | n.SetInteger(1)
17 | ast.Equal(1, n.GetInteger())
18 |
19 | elem := NestedInteger{Num: 1}
20 |
21 | expected := NestedInteger{
22 | Num: 1,
23 | Ns: []*NestedInteger{&elem},
24 | }
25 | n.Add(elem)
26 |
27 | ast.Equal(expected, n)
28 |
29 | ast.Equal(expected.Ns, n.GetList())
30 | }
31 |
--------------------------------------------------------------------------------
/go/z-gopl/ch2/echo4/main.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | // See page 33.
5 | //!+
6 |
7 | // Echo4 prints its command-line arguments.
8 | package main
9 |
10 | import (
11 | "flag"
12 | "fmt"
13 | "strings"
14 | )
15 |
16 | var n = flag.Bool("n", false, "omit trailing newline")
17 | var sep = flag.String("s", " ", "separator")
18 |
19 | func main() {
20 | flag.Parse()
21 | fmt.Print(strings.Join(flag.Args(), *sep))
22 | if !*n {
23 | fmt.Println()
24 | }
25 | }
26 |
27 | //!-
28 |
--------------------------------------------------------------------------------
/interview-list/230909-美团/3.py:
--------------------------------------------------------------------------------
1 | """
2 | 对于一个递增数组, 计算每个元素的差值, 这些差值的不同数量定义为「差异值」, 对于n个数字, 最大限制为m, 求最大的「差异值」
3 | 限制: n,m 1e5
4 | """
5 | n,m = map(int, input().split())
6 | def check(k):
7 | diff = (1+k)*k//2
8 | return m >= diff + n - k
9 | l,r = 0,n-1
10 | mx = 0
11 | while l<=r:
12 | mid = (l+r)//2
13 | if check(mid):
14 | mx = mid
15 | l = mid+1
16 | else:
17 | r = mid-1
18 | acc = 1
19 | ans = [1]
20 | for i in range(mx):
21 | acc += i+1
22 | ans.append(acc)
23 | for i in range(n-mx-1):
24 | acc += 1
25 | ans.append(acc)
26 | print(*ans)
27 |
--------------------------------------------------------------------------------
/test/02.py:
--------------------------------------------------------------------------------
1 | """
2 | 2 5
3 | red book game music sigma
4 | mozart 3
5 | book classic music
6 | arcaea 4
7 | red music game hard
8 | """
9 |
10 | import sys
11 | from collections import defaultdict
12 |
13 | m,n = map(int, sys.stdin.readline().split())
14 | keywords = set(sys.stdin.readline().split())
15 | res = defaultdict(list)
16 | for _ in range(m):
17 | name, _ = sys.stdin.readline().split()
18 | keys = set(sys.stdin.readline().split())
19 | res[len(keys & keywords)].append(name)
20 | for c in sorted(res.keys(), reverse=True):
21 | for name in res[c]:
22 | print(name)
23 |
--------------------------------------------------------------------------------
/LC-contest/luogu/3-普及~提高-/1106/1106.py:
--------------------------------------------------------------------------------
1 | """ P1106 删数问题
2 | 给定一个正整数, 删去其中的k位, 要求结果最小.
3 | 约束: 位数不超过 250
4 | 思路1: #单调栈
5 | 从左往右遍历, 维护一个单调递增栈即可.
6 | 注意: 本题允许数字有前导零, 例如 20018 2 的答案为 1.
7 | """
8 |
9 | nums = list(map(int, input().strip()))
10 | n = len(nums)
11 | k = int(input())
12 | s = []
13 | for num in nums:
14 | while s and s[-1]>num and k:
15 | # if num==0 and len(s)==1: break
16 | s.pop()
17 | k -= 1
18 | s.append(num)
19 | # 当k==0时, s[:-0] = []
20 | s = s[:-k] if k else s
21 | # 注意到转一下int
22 | # 用例: 20018 2, 结果为1; 也即允许出现前导0
23 | print(int("".join(map(str, s))))
--------------------------------------------------------------------------------
/cpp/learn-cpp-heima/135-template-class-inhertance.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | template
6 | class Base {
7 | T m;
8 | };
9 |
10 | //class Son:public Base //错误,c++编译需要给子类分配内存,必须知道父类中T的类型
11 | class Son : public Base {//必须指定一个类型
12 |
13 | };
14 |
15 | template
16 | class Son2 : public Base {
17 | public:
18 | Son2() {
19 | cout << typeid(T1).name() << endl;
20 | cout << typeid(T2).name() << endl;
21 |
22 | }
23 | };
24 |
25 | int main () {
26 | // Son a;
27 |
28 | Son2 a;
29 | }
--------------------------------------------------------------------------------
/go/z-gopl/ch9/memo5/memo_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
2 | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/
3 |
4 | package memo_test
5 |
6 | import (
7 | "testing"
8 |
9 | "gopl.io/ch9/memo5"
10 | "gopl.io/ch9/memotest"
11 | )
12 |
13 | var httpGetBody = memotest.HTTPGetBody
14 |
15 | func Test(t *testing.T) {
16 | m := memo.New(httpGetBody)
17 | defer m.Close()
18 | memotest.Sequential(t, m)
19 | }
20 |
21 | func TestConcurrent(t *testing.T) {
22 | m := memo.New(httpGetBody)
23 | defer m.Close()
24 | memotest.Concurrent(t, m)
25 | }
26 |
--------------------------------------------------------------------------------
/interview-list/230729-Shein/2.py:
--------------------------------------------------------------------------------
1 | """ 最长的没有重复元素的子串长度 返回字符串中, 最长的没有重复元素的子串长度
2 | 限制: n 1e5
3 | """
4 |
5 | def lengthOfLongestSubstring(arr) -> int:
6 | s = set()
7 | l = 0
8 | ans = 0
9 | for r,x in enumerate(arr):
10 | if x in s:
11 | while arr[l] != x:
12 | s.remove(arr[l])
13 | l += 1
14 | l += 1
15 | s.add(x)
16 | ans = max(ans, r-l+1)
17 | return ans
18 |
19 | for a in [
20 | "abcabcbb",
21 | "bbbbb",
22 | "pwwkew",
23 | "",
24 | ]:
25 | print(lengthOfLongestSubstring(a))
26 |
27 |
--------------------------------------------------------------------------------
/js/node/web/koa/use-nunjucks/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "use-nunjucks",
3 | "version": "1.0.0",
4 | "description": "Test nunjucks",
5 | "main": "app.js",
6 | "scripts": {
7 | "start": "node app.js"
8 | },
9 | "keywords": [
10 | "nunjucks",
11 | "templating"
12 | ],
13 | "author": "Michael Liao",
14 | "license": "Apache-2.0",
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/michaelliao/learn-javascript.git"
18 | },
19 | "dependencies": {
20 | "nunjucks": "2.4.2"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/python/beginning-python-3ed-master/README.md:
--------------------------------------------------------------------------------
1 | #Apress Source Code
2 |
3 | This repository accompanies [*Beginning Python*](http://www.apress.com/9781484200292) by Magnus Lie Hetland (Apress, 2017).
4 |
5 | 
6 |
7 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
8 |
9 | ##Releases
10 |
11 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
12 |
13 | ##Contributions
14 |
15 | See the file Contributing.md for more information on how you can contribute to this repository.
16 |
--------------------------------------------------------------------------------
/algorithm-ds-templates/interview-algo-index.md:
--------------------------------------------------------------------------------
1 | ref: 面试题 [[interview-README.md]]
2 | sync: [feishu](https://v0r8x11vrv.feishu.cn/docx/YSvwdxUhwoND1Oxryw7cLCdvnmc)
3 |
4 | # 面试算法精要
5 |
6 | [🔥 LeetCode 热题 HOT 100](https://leetcode.cn/problem-list/2cktkvj/)
7 |
8 | 面试常见题型包括:
9 |
10 | - DP
11 | - 线性, 矩阵, 区间, 树形;
12 | - 二分;
13 | - 图算法
14 | - DFS, BFS, 最短路, 拓扑排序;
15 | - 二叉树;
16 | - 并查集;
17 | - 回溯;
18 |
19 | DP
20 | [[index-DP]]
21 |
22 | 滑动窗口
23 | [[interview-滑窗.md]]
24 |
25 | 二分搜索
26 | [[interview-二分]]
27 |
28 | 图算法
29 | [[interview-图算法]]
30 |
31 | 回溯
32 | [[interview-回溯]]
33 |
34 |
35 |
--------------------------------------------------------------------------------
/cpp/misc/base/06-guess-number.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | using namespace std;
5 |
6 | int main() {
7 | srand((unsigned int)time(NULL)); // 随机种子
8 | int num = rand()%100 + 1;
9 | int val;
10 |
11 | while (1){
12 | cin >> val;
13 | if (val > num){
14 | cout << "Too big." << endl;
15 | } else if (val < num) {
16 | cout << "Too small." << endl;
17 | } else {
18 | cout << "You've got it, the num is " << num << endl;
19 | break;
20 | }
21 | }
22 |
23 |
24 | return 0;
25 | }
--------------------------------------------------------------------------------
/js/from-washu/ReBloom/getStarted.js:
--------------------------------------------------------------------------------
1 | const { BloomFilter } = require('@albert-team/rebloom')
2 |
3 | const main = async () => {
4 | const filter = new BloomFilter('filtername', {
5 | host: 'localhost',
6 | port: 6379,
7 | redisClientOptions: { password: 'scrtpassword' },
8 | })
9 | await filter.connect()
10 |
11 | console.log(await filter.add('item0')) // 1
12 | console.log(await filter.exists('item0')) // 1
13 | console.log(await filter.exists('item1')) // 0
14 |
15 | await filter.disconnect()
16 | }
17 |
18 | main().catch((err) => console.error(err))
19 |
--------------------------------------------------------------------------------