From 120bca22a0d8e28e5e00061df738a6db7f2c339c Mon Sep 17 00:00:00 2001 From: Ultraman <1394466835@qq.com> Date: Sat, 18 May 2024 13:41:19 +0800 Subject: [PATCH] feat: update --- README.md | 1 + kata.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 kata.md diff --git a/README.md b/README.md index e8371eb..68b3ccc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ The best thing to do is have fun. - [列表 - 韩立的修炼](/) - [Hobby Projects](/hobby_projects.md) +- [Kata](/kata.md) - **2024-05** - [如何搭建新个网段,并配有一台机器挂载](/2024/05/new_nic_with_hub_switch.md) - [RC-incubator-answer 论坛](/2024/05/incubator-answer.md) diff --git a/kata.md b/kata.md new file mode 100644 index 0000000..baea71c --- /dev/null +++ b/kata.md @@ -0,0 +1,42 @@ +# What can i say + +## [114. Flatten Binary Tree to Linked List](https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/) + +如果使用 O(n) space 比较简单,前序遍历回放即可。 + +O(1) space 的话,利用递归思想 flatten(left), flatten(right),最后再将 right, left 合并。 + +## [199. Binary Tree Right Side View](https://leetcode.cn/problems/binary-tree-right-side-view/) + +层序遍历,每层取最后一个元素 + +## [2462. Total Cost to Hire K Workers](https://leetcode.cn/problems/total-cost-to-hire-k-workers/) + +使用两个堆一个维护前面的,一个维护后面的最小 cost +需要注意两个堆中元素不能重复即(2\*candidates+k<=n),如果元素不足,而可以直接排序取。 + +## [1329. Sort the Matrix Diagonally](https://leetcode.cn/problems/sort-the-matrix-diagonally/) + +对角线特性,同一对角线的元素 i-j 都相等,可以先收集,排序,放回。 + +[数学解法](https://leetcode.cn/problems/sort-the-matrix-diagonally/solutions/2760094/dui-jiao-xian-pai-xu-fu-yuan-di-pai-xu-p-uts8/) + +## [1. Two Sum](https://leetcode.cn/problems/two-sum/) + +字典运用 + +## [1017. Convert to Base -2](https://leetcode.cn/problems/convert-to-base-2/) + +十进制 转 X 进制 + +``` + n = a * (x)^5 + b * (x)^4 + c * (x)^3 + d * (x)^2 + e * (x)^1 + f * (x)^0 +``` + +本质就是求 abcdef,可以每次求出 f(n%x),然后 n-f,n//=x 就是下一个 + +## [2007. Find Original Array From Doubled Array](https://leetcode.cn/problems/find-original-array-from-doubled-array/) + +首先排序,每次配对最小的元素 + +## [Training on Decode the Morse code | Codewars](https://www.codewars.com/kata/54b724efac3d5402db00065e/train/go)