refactor: convert all LeetCode solutions to Go-only
Changes: - Removed all Java code implementations - Kept only Go language solutions - Renamed "## Go 解法" to "## 解法" - Removed "### Go 代码要点" sections - Cleaned up duplicate headers and empty sections - Streamlined documentation for better readability Updated files (9): - 三数之和.md - 两数相加.md - 无重复字符的最长子串.md - 最长回文子串.md - 括号生成.md - 子集.md - 单词搜索.md - 电话号码的字母组合.md - 柱状图中最大的矩形.md All 22 LeetCode Hot 100 Medium problems now use Go exclusively. Code is cleaner, more focused, and easier to follow. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -57,8 +57,6 @@ nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 解法
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 图解过程
|
## 图解过程
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ LeetCode 2. Medium
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 解法
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 进阶问题
|
## 进阶问题
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ func exist(board [][]byte, word string) bool {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
**LeetCode 212:** 给定一个 m x n 二维字符网格 board 和一个单词列表 words,返回所有在二维网格和字典中出现的单词。
|
**LeetCode 212:** 给定一个 m x n 二维字符网格 board 和一个单词列表 words,返回所有在二维网格和字典中出现的单词。
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func subsetsBitMask(nums []int) [][]int {
|
func subsetsBitMask(nums []int) [][]int {
|
||||||
n := len(nums)
|
n := len(nums)
|
||||||
@@ -136,7 +135,6 @@ func subsetsBitMask(nums []int) [][]int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func subsetsCascade(nums []int) [][]int {
|
func subsetsCascade(nums []int) [][]int {
|
||||||
result := [][]int{{}} // 初始化为空集
|
result := [][]int{{}} // 初始化为空集
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func generateParenthesisDP(n int) []string {
|
func generateParenthesisDP(n int) []string {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -162,7 +161,6 @@ func generateParenthesisDP(n int) []string {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
- **时间复杂度:** O(4^n / √n)
|
- **时间复杂度:** O(4^n / √n)
|
||||||
- 在回溯树中,每个节点最多有 2 个分支
|
- 在回溯树中,每个节点最多有 2 个分支
|
||||||
- 树的高度为 2n
|
- 树的高度为 2n
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ LeetCode 3. Medium
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Go 解法
|
## 解法
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func lengthOfLongestSubstring(s string) int {
|
func lengthOfLongestSubstring(s string) int {
|
||||||
@@ -74,16 +74,8 @@ func lengthOfLongestSubstring(s string) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Go 代码要点
|
|
||||||
1. 使用 `range` 遍历字符串,自动处理 Unicode
|
|
||||||
2. `map[rune]int` 记录字符索引
|
|
||||||
3. 条件判断:`idx >= left` 确保在窗口内
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 解法
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 图解过程
|
## 图解过程
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func longestPalindromeDP(s string) string {
|
func longestPalindromeDP(s string) string {
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
@@ -175,7 +174,6 @@ func longestPalindromeDP(s string) string {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func longestPalindromeManacher(s string) string {
|
func longestPalindromeManacher(s string) string {
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
|
|||||||
@@ -52,6 +52,5 @@ func largestRectangleArea(heights []int) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
- LeetCode 85: 最大矩形(二维版本)
|
- LeetCode 85: 最大矩形(二维版本)
|
||||||
- LeetCode 42: 接雨水
|
- LeetCode 42: 接雨水
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func letterCombinationsIterative(digits string) []string {
|
func letterCombinationsIterative(digits string) []string {
|
||||||
if digits == "" {
|
if digits == "" {
|
||||||
@@ -191,7 +190,6 @@ func letterCombinationsIterative(digits string) []string {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
- **时间复杂度:** O(3^m × 4^n)
|
- **时间复杂度:** O(3^m × 4^n)
|
||||||
- 其中 m 是对应 3 个字母的数字个数(2, 3, 4, 5, 6, 8)
|
- 其中 m 是对应 3 个字母的数字个数(2, 3, 4, 5, 6, 8)
|
||||||
- n 是对应 4 个字母的数字个数(7, 9)
|
- n 是对应 4 个字母的数字个数(7, 9)
|
||||||
|
|||||||
Reference in New Issue
Block a user