Skip to content

Instantly share code, notes, and snippets.

@leftrk
leftrk / page.js
Created December 10, 2020 09:53
liaoxuefeng.com 左右方向键翻页
// ==UserScript==
// @name liaoxuefeng.com 左右方向键翻页
// @description liaoxuefeng.com 教程 增加翻页功能
// @namespace Big Scripts
// @match *://www.liaoxuefeng.com/wiki/*
// @grant none
// @require https://code.jquery.com/jquery-3.5.1.min.js
// @version 0.0.1
// ==/UserScript==
@leftrk
leftrk / download.py
Created December 11, 2019 18:37
download file
def downloadFILE(url, name):
resp = requests.get(url=url, stream=True)
content_size = int(resp.headers['Content-Length']) / 1024
with open(name, "wb") as f:
print("File total size is:", content_size, 'k,start...')
for data in tqdm(iterable=resp.iter_content(1024), total=content_size + 1, unit='k', desc=name):
f.write(data)
print(name + " download finished!")
@leftrk
leftrk / gist:2b66466353d61f7232fff30181dd943d
Last active May 28, 2019 13:49
二分查找的不完全总结
/*
* 1. right = nums.size()
* 2. left < right
* 3. right = mid
* 4. return right
*/
int find(vector<int> &nums, int target) {
int left = 0, right = nums.size();
#include "leetcode.h"
class Solution {
public:
// 关键点:把 nums 塞入 value 中
void build_segment_tree(vector<int> &value, // 线段数组 value, 存储区间 sum
vector<int> &nums, // 原始数组 nums
int pos, // 当前线段【节点】在线段数组 value 中的下标
int left, // 当前线段的左端点
@leftrk
leftrk / bucketSort.cpp
Created January 29, 2019 06:59
桶排序
#define CATCH_CONFIG_MAIN
//#include "catch.hpp"
/**
* function bucket-sort(array, n) is
* bucket <- new array of n empty lists
*
* for i = 0 to (length(array)-1) do
* insert array[i] into buckets[msbits(array[i], )]
@leftrk
leftrk / Node.cpp
Created December 9, 2018 09:51
双向链表
template<typename Object>
struct Node {
Object data;
Node *prev;
Node *next;
Node(const Object &d = Object{}, Node *p = nullptr, Node *n = nullptr)
: data{d}, prev{p}, next{n} {}
Node(Object &&d, Node *p = nullptr, Node *n = nullptr)
@leftrk
leftrk / Vector.cpp
Created December 9, 2018 09:46
Vector
template<typename Object>
class Vector {
private:
int theSize;
int theCapacity;
Object *objects;
static const int SPARE_CAPACITY = 16;
public:
@leftrk
leftrk / pow.cpp
Created December 7, 2018 08:38
高效率的幂运算
long long pow(long long x, int n) {
if (n == 0)
return 1;
if (n == 1)
return x;
if (n & 0x1)
return pow(x * x, n / 2) * x;
else
return pow(x * x, n / 2);
}
@leftrk
leftrk / gcd.cpp
Created December 7, 2018 08:36
欧几里得算法
long long gcd(long long m, long long n) {
while (n != 0) {
long long rem = m % n;
m = n;
n = rem;
}
return m;
}
@leftrk
leftrk / maxSubSum3.cpp
Last active December 6, 2018 18:57
相连最大子序列和的分治算法O(nlog(n))
/**
* @param a
* @param left
* @param right
* @return maxSum between left and right
* @brief 相连最大子序列和的递归算法
* @note 找出生成 [left ... right] 的子数组的最大和,不试图保留具体的最佳序列
*/
int maxSumRec(const vector<int> &a, int left, int right) {
if (left == right) // 基准情形