Skip to content

Commit e4d867c

Browse files
committed
Setting for jupyter notebook
1 parent 023056b commit e4d867c

932 files changed

Lines changed: 91224 additions & 86339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.markdownlint.json

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
{
2-
"default": true,
3-
"MD013": {
4-
"line_length": 100,
5-
"code_blocks": false,
6-
"tables": false
7-
},
8-
"MD033": {
9-
"allowed_elements": [
10-
"h1",
11-
"h2",
12-
"details",
13-
"summary",
14-
"p",
15-
"i",
16-
"footer",
17-
"div"
18-
]
19-
}
2+
"default": true,
3+
"MD013": {
4+
"line_length": 100,
5+
"code_blocks": false,
6+
"tables": false
7+
},
8+
"MD033": {
9+
"allowed_elements": ["h1", "h2", "details", "summary", "p", "i", "footer", "div"]
10+
}
2011
}

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.11

Algorithm/Backtracking/leetcode/22. Generate Parentheses/GenerateParentheses.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// ```javascript
77
/**
88
* n個の括弧の全ての正しい組み合わせを生成します
9-
*
9+
*
1010
* @param {number} n - 括弧のペア数(1 <= n <= 8)
1111
* @returns {string[]} - 全ての正しい括弧の組み合わせ
12-
*
12+
*
1313
* 時間計算量: O(4^n / sqrt(n)) (カタラン数)
1414
* メモリ消費量: O(4^n / sqrt(n)) (結果配列と呼び出しスタック)
1515
*/
@@ -18,7 +18,7 @@ function generateParenthesisJs(n) {
1818

1919
/**
2020
* バックトラッキングで括弧を追加
21-
*
21+
*
2222
* @param {string} current - 現在の括弧列
2323
* @param {number} open - 残り使える開き括弧の数
2424
* @param {number} close - 残り使える閉じ括弧の数
@@ -31,16 +31,16 @@ function generateParenthesisJs(n) {
3131

3232
// 開き括弧を追加
3333
if (open > 0) {
34-
backtrack(current + "(", open - 1, close);
34+
backtrack(current + '(', open - 1, close);
3535
}
3636

3737
// 閉じ括弧を追加(開き括弧より多くは使えない)
3838
if (close > open) {
39-
backtrack(current + ")", open, close - 1);
39+
backtrack(current + ')', open, close - 1);
4040
}
4141
}
4242

43-
backtrack("", n, n);
43+
backtrack('', n, n);
4444

4545
return result;
4646
}
@@ -92,7 +92,7 @@ function generateParenthesisJs(n) {
9292
// └─ ")" -> "(())"
9393
// └─ "(" -> "(())("
9494
// └─ ")" -> "(())()" [解]
95-
// └─ ")" -> "()"
95+
// └─ ")" -> "()"
9696
// └─ "(" -> "()("
9797
// └─ "(" -> "()(("
9898
// └─ ")" -> "(()()"
@@ -101,4 +101,3 @@ function generateParenthesisJs(n) {
101101
// └─ "(" -> "()()("
102102
// └─ ")" -> "()()()" [解]
103103
// ```
104-

Algorithm/Backtracking/leetcode/22. Generate Parentheses/GenerateParentheses.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ function generateParenthesis(n: number): string[] {
3030
}
3131

3232
if (open > 0) {
33-
backtrack(current + "(", open - 1, close);
33+
backtrack(current + '(', open - 1, close);
3434
}
3535

3636
if (close > open) {
37-
backtrack(current + ")", open, close - 1);
37+
backtrack(current + ')', open, close - 1);
3838
}
3939
}
4040

41-
backtrack("", n, n);
41+
backtrack('', n, n);
4242

4343
return result;
4444
}

Algorithm/Backtracking/leetcode/22. Generate Parentheses/README.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ close = 3
3737

3838
### **処理:バックトラッキング(再帰)**
3939

40-
* **「(」はまだ残っていれば追加可能**
41-
* **「)」は、現在使った「(」より多くは使えない**
40+
- **「(」はまだ残っていれば追加可能**
41+
- **「)」は、現在使った「(」より多くは使えない**
4242

4343
---
4444

@@ -65,13 +65,13 @@ close = 3
6565

6666
### **各ノードの意味**
6767

68-
| ノード | 意味 |
69-
| ---------- | --------------------- |
68+
| ノード | 意味 |
69+
| ---------- | ----------------------------------------- |
7070
| `"((("` | 開き括弧3つ追加。閉じ括弧はまだ使えない。 |
71-
| `"(()"` | 開き括弧2つ、閉じ括弧1つ。 |
72-
| `"(()())"` | 完成パターン(正しい) |
73-
| `"((()))"` | 完成パターン(正しい) |
74-
| `"()()()"` | 完成パターン(正しい) |
71+
| `"(()"` | 開き括弧2つ、閉じ括弧1つ。 |
72+
| `"(()())"` | 完成パターン(正しい) |
73+
| `"((()))"` | 完成パターン(正しい) |
74+
| `"()()()"` | 完成パターン(正しい) |
7575

7676
---
7777

@@ -80,16 +80,16 @@ close = 3
8080
### **引数の管理**
8181

8282
| current | 現在構築中の文字列 |
83-
| ------- | ---------- |
83+
| ------- | ------------------- |
8484
| open | 残り使える「(」の数 |
8585
| close | 残り使える「)」の数 |
8686

8787
---
8888

8989
## **4. 制約と枝刈り**
9090

91-
* `open > 0` → 「(」を追加
92-
* `close > open` → 「)」を追加(ただし「(」の数より多くは使えない)
91+
- `open > 0` → 「(」を追加
92+
- `close > open` → 「)」を追加(ただし「(」の数より多くは使えない)
9393

9494
### **図での枝刈り**
9595

@@ -105,14 +105,14 @@ current = ")(" → NG!(無視)← 不正な場合は探索しない
105105

106106
#### **「(()())」ができる流れ**
107107

108-
| current | open | close | |
109-
| -------- | ---- | ----- | ----- |
110-
| "" | 3 | 3 | |
111-
| "(" | 2 | 3 | |
112-
| "((" | 1 | 3 | |
113-
| "(()" | 1 | 2 | |
114-
| "(()(" | 0 | 2 | |
115-
| "(()()" | 0 | 1 | |
108+
| current | open | close | |
109+
| -------- | ---- | ----- | --------- |
110+
| "" | 3 | 3 | |
111+
| "(" | 2 | 3 | |
112+
| "((" | 1 | 3 | |
113+
| "(()" | 1 | 2 | |
114+
| "(()(" | 0 | 2 | |
115+
| "(()()" | 0 | 1 | |
116116
| "(()())" | 0 | 0 | ✅ 完成! |
117117

118118
---
@@ -129,23 +129,23 @@ $$
129129

130130
例:
131131

132-
| n | 組み合わせ数 |
133-
| - | ------ |
134-
| 1 | 1 |
135-
| 2 | 2 |
136-
| 3 | 5 |
137-
| 4 | 14 |
138-
| 5 | 42 |
139-
| 6 | 132 |
140-
| 7 | 429 |
141-
| 8 | 1430 |
132+
| n | 組み合わせ数 |
133+
| --- | ------------ |
134+
| 1 | 1 |
135+
| 2 | 2 |
136+
| 3 | 5 |
137+
| 4 | 14 |
138+
| 5 | 42 |
139+
| 6 | 132 |
140+
| 7 | 429 |
141+
| 8 | 1430 |
142142

143143
---
144144

145145
### **時間・空間計算量**
146146

147-
| 項目 | 計算量 |
148-
| ----- | ----------- |
147+
| 項目 | 計算量 |
148+
| ---------- | ----------- |
149149
| 時間計算量 | O(4^n / √n) |
150150
| 空間計算量 | O(4^n / √n) |
151151

@@ -158,11 +158,11 @@ $$
158158

159159
### **このアルゴリズムの特徴**
160160

161-
| 項目 | 内容 |
162-
| ----- | ------------------- |
163-
| 効率性 | 不要な組み合わせを生成しない(枝刈り) |
164-
| シンプルさ | 再帰+状態管理のみ |
165-
| メモリ | 結果+再帰スタックだけ使用 |
161+
| 項目 | 内容 |
162+
| ---------- | -------------------------------------- |
163+
| 効率性 | 不要な組み合わせを生成しない(枝刈り) |
164+
| シンプルさ | 再帰+状態管理のみ |
165+
| メモリ | 結果+再帰スタックだけ使用 |
166166

167167
---
168168

@@ -175,4 +175,3 @@ $$
175175
└─ NO: ( と ) の両方試す(ただし「)」はopen < close)
176176
└─ 完成したら result に追加
177177
```
178-

Algorithm/Backtracking/leetcode/39. Combination Sum/Claude/Combination-Sum.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// 3. **インデックス管理**: 同じ要素を重複使用する際に`startIndex`を固定し、順序を保つことで重複組み合わせを防止
1616
// 4. **メモリ効率**: 組み合わせを動的に構築・削除することでメモリ使用量を最小化
1717

18-
// **時間計算量**: O(N^(T/M))
18+
// **時間計算量**: O(N^(T/M))
1919
// - N: candidates配列の長さ
2020
// - T: target値
2121
// - M: candidatesの最小値
@@ -29,12 +29,12 @@
2929
* @param {number} target - 目標とする合計値
3030
* @return {number[][]} - 目標値に達する全ての組み合わせの配列
3131
*/
32-
var combinationSum = function(candidates, target) {
32+
var combinationSum = function (candidates, target) {
3333
const result = [];
34-
34+
3535
// 配列をソートして早期終了を可能にする
3636
candidates.sort((a, b) => a - b);
37-
37+
3838
/**
3939
* バックトラッキングで組み合わせを探索
4040
* @param {number} startIndex - 探索開始インデックス
@@ -47,26 +47,26 @@ var combinationSum = function(candidates, target) {
4747
result.push([...currentCombination]);
4848
return;
4949
}
50-
50+
5151
for (let i = startIndex; i < candidates.length; i++) {
5252
const candidate = candidates[i];
53-
53+
5454
// 候補値が残り目標値より大きい場合、以降の候補も大きいので終了
5555
if (candidate > remainingTarget) {
5656
break;
5757
}
58-
58+
5959
// 現在の候補を組み合わせに追加
6060
currentCombination.push(candidate);
61-
61+
6262
// 同じ候補を再度使用可能なので、startIndexは変更しない
6363
backtrack(i, currentCombination, remainingTarget - candidate);
64-
64+
6565
// バックトラック:候補を削除
6666
currentCombination.pop();
6767
}
6868
}
69-
69+
7070
backtrack(0, [], target);
7171
return result;
72-
};
72+
};

Algorithm/Backtracking/leetcode/39. Combination Sum/Claude/Combination-Sum.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,46 @@
3030
*/
3131
function combinationSumClaude(candidates: number[], target: number): number[][] {
3232
const result: number[][] = [];
33-
33+
3434
// 配列をソートして早期終了を可能にする
3535
candidates.sort((a, b) => a - b);
36-
36+
3737
/**
3838
* バックトラッキングで組み合わせを探索
3939
* @param startIndex - 探索開始インデックス
4040
* @param currentCombination - 現在の組み合わせ
4141
* @param remainingTarget - 残りの目標値
4242
*/
43-
function backtrack(startIndex: number, currentCombination: number[], remainingTarget: number): void {
43+
function backtrack(
44+
startIndex: number,
45+
currentCombination: number[],
46+
remainingTarget: number,
47+
): void {
4448
// 目標値に達した場合、結果に追加
4549
if (remainingTarget === 0) {
4650
result.push([...currentCombination]);
4751
return;
4852
}
49-
53+
5054
for (let i: number = startIndex; i < candidates.length; i++) {
5155
const candidate: number = candidates[i];
52-
56+
5357
// 候補値が残り目標値より大きい場合、以降の候補も大きいので終了
5458
if (candidate > remainingTarget) {
5559
break;
5660
}
57-
61+
5862
// 現在の候補を組み合わせに追加
5963
currentCombination.push(candidate);
60-
64+
6165
// 同じ候補を再度使用可能なので、startIndexは変更しない
6266
backtrack(i, currentCombination, remainingTarget - candidate);
63-
67+
6468
// バックトラック:候補を削除
6569
currentCombination.pop();
6670
}
6771
}
68-
72+
6973
backtrack(0, [], target);
7074
return result;
71-
};
75+
}

0 commit comments

Comments
 (0)