Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8a09ed

Browse files
update: 230
1 parent 95c2db4 commit d8a09ed

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
131131
| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/) | [JavaScript](./src/contains-duplicate-ii/res.js) | Easy |
132132
| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii/) | [JavaScript](./src/contains-duplicate-iii/res.js) | Medium |
133133
| 228 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/solution/) | [JavaScript](./src/summary-ranges/res.js) | Medium |
134+
| 230 | [kth-smallest-element-in-a-bst](https://leetcode.com/problems/kth-smallest-element-in-a-bst/solution/) | [TypeScript](./src/kth-smallest-element-in-a-bst/res.ts) | Medium |
134135
| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/solution/) | [JavaScript](./src/product-of-array-except-self/res.js) | Medium |
135136
| 239 | [Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/description/) | [JavaScript](./src/sliding-window-maximum/description/res.js) | Hard |
136137
| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/) | [JavaScript](./src/search-a-2d-matrix-ii/res.js) · [TypeScript](./src/search-a-2d-matrix-ii/res.ts) | Medium |
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* class TreeNode {
4+
* val: number
5+
* left: TreeNode | null
6+
* right: TreeNode | null
7+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
8+
* this.val = (val===undefined ? 0 : val)
9+
* this.left = (left===undefined ? null : left)
10+
* this.right = (right===undefined ? null : right)
11+
* }
12+
* }
13+
*/
14+
15+
const getTreeList = (root: TreeNode | null): number[] => {
16+
if (!root) {
17+
return [];
18+
}
19+
20+
const result = [];
21+
22+
result.push(...getTreeList(root.left));
23+
result.push(root.val);
24+
result.push(...getTreeList(root.right));
25+
26+
return result;
27+
}
28+
29+
function kthSmallest(root: TreeNode | null, k: number): number {
30+
const result = getTreeList(root);
31+
32+
return result[k-1];
33+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /