Skip to content

Commit 82ab04d

Browse files
author
刘晓东
committed
Merge branch 'master' of https://github.com/L-SUI/note
2 parents 0351326 + 068ab46 commit 82ab04d

10 files changed

+596
-7864
lines changed

.circleci/config.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#https://github.com/revolunet/create-react-app-circleci/blob/master/.circleci/config.yml
2+
# 给当前node_modules 一个快照,如果 package.json 没变,node_modules 就不用重新下载
3+
defaults: &defaults
4+
docker:
5+
- image: circleci/node:12.18.2
6+
7+
version: 2
8+
jobs:
9+
publish:
10+
<<: *defaults
11+
steps:
12+
- checkout
13+
- run: git pull
14+
- restore_cache:
15+
keys:
16+
- v2-dependencies-{{ checksum "package.json" }}
17+
- run: npm install
18+
- save_cache:
19+
paths:
20+
- node_modules
21+
key: v2-dependencies-{{ checksum "package.json" }}
22+
- run: npm install -D vuepress --registry.npmjs.org
23+
# ksgcLbaW4SVNXtGtudlBOZ2EfMJz80TMlqpNi934
24+
- run: npx vuepress build docs
25+
- run: rm -rf ./L-SUI.github.io
26+
- run: git clone https://github.com/L-SUI/L-SUI.github.io.git
27+
- run: cp -af ./docs/.vuepress/dist/ ./L-SUI.github.io/
28+
- run: cd L-SUI.github.io && git add .
29+
- run: git config user.email "[email protected]"
30+
- run: git config user.name "LiuXiaoDong"
31+
- run: git commit -m 'circleci自动提交'
32+
- run: git push
33+
- run: cd ../ && rm -rf ./L-SUI.github.io
34+
# - persist_to_workspace:
35+
# root: .
36+
# paths:
37+
# - node_modules
38+
39+
40+
workflows:
41+
version: 2
42+
build_accept_deploy:
43+
jobs:
44+
- publish
45+
# - prepare
46+
# - publish:
47+
# requires:
48+
# - prepare
49+
# - prepare
50+
# - build:
51+
# requires:
52+
# - test
53+
# - test:
54+
# requires:
55+
# - prepare
56+
# requires:
57+
# - build
58+
# filters:
59+
# # 所有 branches 都忽略,只部署 vx.x.x 的 tags
60+
## tags:
61+
## only: /^v[0-9]+(\.[0-9]+)*/
62+
# branches:
63+
# all
64+
# ignore: /.*/

LeetCode/1160. 拼写单词.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// 给你一份『词汇表』(字符串数组) words 和一张『字母表』(字符串) chars。
2+
3+
// 假如你可以用 chars 中的『字母』(字符)拼写出 words 中的某个『单词』(字符串),那么我们就认为你掌握了这个单词。
4+
5+
// 注意:每次拼写(指拼写词汇表中的一个单词)时,chars 中的每个字母都只能用一次。
6+
7+
// 返回词汇表 words 中你掌握的所有单词的 长度之和。
8+
9+
//  
10+
11+
// 示例 1:
12+
13+
// 输入:words = ["cat","bt","hat","tree"], chars = "atach"
14+
// 输出:6
15+
// 解释:
16+
// 可以形成字符串 "cat" 和 "hat",所以答案是 3 + 3 = 6。
17+
// 示例 2:
18+
19+
// 输入:words = ["hello","world","leetcode"], chars = "welldonehoneyr"
20+
// 输出:10
21+
// 解释:
22+
// 可以形成字符串 "hello" 和 "world",所以答案是 5 + 5 = 10。
23+
//  
24+
25+
// 提示:
26+
27+
// 1 <= words.length <= 1000
28+
// 1 <= words[i].length, chars.length <= 100
29+
// 所有字符串中都仅包含小写英文字母
30+
31+
32+
// 来源:力扣(LeetCode)
33+
// 链接:https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters
34+
// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
35+
36+
37+
38+
39+
/**
40+
* @param {string[]} words
41+
* @param {string} chars
42+
* @return {number}
43+
*/
44+
/**
45+
* @param {string[]} words
46+
* @param {string} chars
47+
* @return {number}
48+
*/
49+
var countCharacters = function(words, chars) {
50+
let size = 0;
51+
let charMap = new Map();
52+
53+
for(let char of chars) {
54+
charMap.set(char, (charMap.has(char) ? charMap.get(char) + 1 : 1));
55+
}
56+
for(let word of words) {
57+
let wordMap = new Map();
58+
for(let char of word) {
59+
wordMap.set(char, (wordMap.has(char) ? wordMap.get(char) + 1 : 1));
60+
}
61+
let enough = true;
62+
for(let char of word) {
63+
if(wordMap.get(char) > charMap.get(char) || charMap.get(char) === undefined) {
64+
enough = false;
65+
break;
66+
}
67+
}
68+
if(enough) {
69+
size += word.length;
70+
}
71+
}
72+
return size;
73+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// 请你设计一个支持下述操作的栈。
2+
3+
// 实现自定义栈类 CustomStack :
4+
5+
// CustomStack(int maxSize):用 maxSize 初始化对象,maxSize 是栈中最多能容纳的元素数量,栈在增长到 maxSize 之后则不支持 push 操作。
6+
// void push(int x):如果栈还未增长到 maxSize ,就将 x 添加到栈顶。
7+
// int pop():弹出栈顶元素,并返回栈顶的值,或栈为空时返回 -1 。
8+
// void inc(int k, int val):栈底的 k 个元素的值都增加 val 。如果栈中元素总数小于 k ,则栈中的所有元素都增加 val 。
9+
//  
10+
11+
// 示例:
12+
13+
// 输入:
14+
// ["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]
15+
// [[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]
16+
// 输出:
17+
// [null,null,null,2,null,null,null,null,null,103,202,201,-1]
18+
// 解释:
19+
// CustomStack customStack = new CustomStack(3); // 栈是空的 []
20+
// customStack.push(1); // 栈变为 [1]
21+
// customStack.push(2); // 栈变为 [1, 2]
22+
// customStack.pop(); // 返回 2 --> 返回栈顶值 2,栈变为 [1]
23+
// customStack.push(2); // 栈变为 [1, 2]
24+
// customStack.push(3); // 栈变为 [1, 2, 3]
25+
// customStack.push(4); // 栈仍然是 [1, 2, 3],不能添加其他元素使栈大小变为 4
26+
// customStack.increment(5, 100); // 栈变为 [101, 102, 103]
27+
// customStack.increment(2, 100); // 栈变为 [201, 202, 103]
28+
// customStack.pop(); // 返回 103 --> 返回栈顶值 103,栈变为 [201, 202]
29+
// customStack.pop(); // 返回 202 --> 返回栈顶值 202,栈变为 [201]
30+
// customStack.pop(); // 返回 201 --> 返回栈顶值 201,栈变为 []
31+
// customStack.pop(); // 返回 -1 --> 栈为空,返回 -1
32+
//  
33+
34+
// 提示:
35+
36+
// 1 <= maxSize <= 1000
37+
// 1 <= x <= 1000
38+
// 1 <= k <= 1000
39+
// 0 <= val <= 100
40+
// 每种方法 increment,push 以及 pop 分别最多调用 1000 次
41+
42+
43+
44+
45+
/**
46+
* @param {number} maxSize
47+
*/
48+
var CustomStack = function(maxSize) {
49+
this.queue = [];
50+
this.maxSize = maxSize
51+
};
52+
53+
/**
54+
* @param {number} x
55+
* @return {void}
56+
*/
57+
CustomStack.prototype.push = function(x) {
58+
if(this.queue.length<this.maxSize) this.queue.push(x)
59+
};
60+
61+
/**
62+
* @return {number}
63+
*/
64+
CustomStack.prototype.pop = function() {
65+
if(this.queue.length==0) return -1;
66+
return this.queue.pop()
67+
};
68+
69+
/**
70+
* @param {number} k
71+
* @param {number} val
72+
* @return {void}
73+
*/
74+
CustomStack.prototype.increment = function(k, val) {
75+
let i=0;
76+
while(i<k&&i<this.queue.length){
77+
this.queue[i] += val
78+
i++
79+
}
80+
};
81+
82+
/**
83+
* Your CustomStack object will be instantiated and called as such:
84+
* var obj = new CustomStack(maxSize)
85+
* obj.push(x)
86+
* var param_2 = obj.pop()
87+
* obj.increment(k,val)
88+
*/
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// 给你一个链表数组,每个链表都已经按升序排列。
2+
3+
// 请你将所有链表合并到一个升序链表中,返回合并后的链表。
4+
5+
//  
6+
7+
// 示例 1:
8+
9+
// 输入:lists = [[1,4,5],[1,3,4],[2,6]]
10+
// 输出:[1,1,2,3,4,4,5,6]
11+
// 解释:链表数组如下:
12+
// [
13+
// 1->4->5,
14+
// 1->3->4,
15+
// 2->6
16+
// ]
17+
// 将它们合并到一个有序链表中得到。
18+
// 1->1->2->3->4->4->5->6
19+
// 示例 2:
20+
21+
// 输入:lists = []
22+
// 输出:[]
23+
// 示例 3:
24+
25+
// 输入:lists = [[]]
26+
// 输出:[]
27+
//  
28+
29+
// 提示:
30+
31+
// k == lists.length
32+
// 0 <= k <= 10^4
33+
// 0 <= lists[i].length <= 500
34+
// -10^4 <= lists[i][j] <= 10^4
35+
// lists[i] 按 升序 排列
36+
// lists[i].length 的总和不超过 10^4
37+
38+
39+
// 来源:力扣(LeetCode)
40+
// 链接:https://leetcode-cn.com/problems/merge-k-sorted-lists
41+
// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
42+
43+
44+
45+
46+
/**
47+
* Definition for singly-linked list.
48+
* function ListNode(val, next) {
49+
* this.val = (val===undefined ? 0 : val)
50+
* this.next = (next===undefined ? null : next)
51+
* }
52+
*/
53+
/**
54+
* @param {ListNode[]} lists
55+
* @return {ListNode}
56+
*/
57+
/**
58+
* @param {ListNode[]} lists
59+
* @return {ListNode}
60+
*/
61+
var mergeKLists = function (lists) {
62+
// 当是空数组的情况下
63+
if (!lists.length) {
64+
return null;
65+
}
66+
// 合并两个排序链表
67+
const merge = (head1, head2) => {
68+
let dummy = new ListNode(0);
69+
let cur = dummy;
70+
// 新链表,新的值小就先接谁
71+
while (head1 && head2) {
72+
if (head1.val < head2.val) {
73+
cur.next = head1;
74+
head1 = head1.next;
75+
} else {
76+
cur.next = head2;
77+
head2 = head2.next;
78+
}
79+
cur = cur.next;
80+
}
81+
// 如果后面还有剩余的就把剩余的接上
82+
cur.next = head1 == null ? head2 : head1;
83+
return dummy.next;
84+
};
85+
const mergeLists = (lists, start, end) => {
86+
if (start + 1 == end) {
87+
return lists[start];
88+
}
89+
// 输入的k个排序链表,可以分成两部分,前k/2个链表和后k/2个链表
90+
// 如果将这前k/2个链表和后k/2个链表分别合并成两个排序的链表,再将两个排序的链表合并,那么所有链表都合并了
91+
let mid = (start + end) >> 1;
92+
let head1 = mergeLists(lists, start, mid);
93+
let head2 = mergeLists(lists, mid, end);
94+
return merge(head1, head2);
95+
};
96+
return mergeLists(lists, 0, lists.length);
97+
};
98+
99+

0 commit comments

Comments
 (0)