摘要: 15. 三数之和 - 力扣(LeetCode) 思路 双指针法 1. 对输入数组进行校验,是否符合输入要求。 2. 对数组进行排序。 检查排序后的第一个元素,如果第一个元素大于零,则它和任何其他两个元素相加都大于零。返回空值。 3. 首先对数组进行遍历,确定第一个元素V1。 4. 对第一个元素之后的 阅读全文
posted @ 2022-05-21 23:53 SoutherLea 阅读(16) 评论(0) 推荐(0) 编辑
摘要: 11. 盛最多水的容器 - 力扣(LeetCode) 思路1 双循环(超时了) 1. 确定计算公式 res = min(height[i], height[j]) * (j - i) 2.使用双循环计算出所有的值,保留最大值。 func maxArea(height []int) int { res 阅读全文
posted @ 2022-05-21 23:26 SoutherLea 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 274. H 指数 - 力扣(LeetCode) 思路 func hIndex(citations []int) int { h := 0 sort.Ints(citations) for i := len(citations) - 1; i >= 0 && citations[i] > h; i- 阅读全文
posted @ 2022-05-10 04:51 SoutherLea 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 498. 对角线遍历 - 力扣(LeetCode) 思路 找规律 1. 设x,y为数组下标,x+y为偶数时,向右上遍历。x+y为奇数时,向左下遍历。 2. 在向左下遍历时 先考虑边界1 当前在最后一行,则向右移动一格 y+1;再考虑边界 2 当前在第一列,向下移动一格 x+1; 其他情况 x+1,y 阅读全文
posted @ 2022-05-10 04:30 SoutherLea 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 79. 单词搜索 - 力扣(LeetCode) 思路 还是回溯 func exist(board [][]byte, word string) bool { if len(board) < 1 || len(board[0]) > 6 || len(word) > 15 || len(word) < 阅读全文
posted @ 2022-05-10 02:34 SoutherLea 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 494. 目标和 - 力扣(LeetCode) 思路 依然是回溯法 func findTargetSumWays(nums []int, target int) int { res := 0 if len(nums) == 0 { return 0 } var backTracking func(n 阅读全文
posted @ 2022-05-10 00:29 SoutherLea 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 17. 电话号码的字母组合 - 力扣(LeetCode) 思路 回溯法 func letterCombinations(digits string) []string { if len(digits) == 0 || len(digits) > 4 { return nil } strMap := 阅读全文
posted @ 2022-05-09 22:54 SoutherLea 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 22. 括号生成 - 力扣(LeetCode) 思路 深度优先遍历 func generateParenthesis(n int) []string { res := make([]string, 0) var dfs func(temp string, leftCount int, rightCo 阅读全文
posted @ 2022-05-09 21:42 SoutherLea 阅读(13) 评论(0) 推荐(0) 编辑
摘要: 39. 组合总和 - 力扣(LeetCode) 思路 回溯 还是以递归全排列+剪枝来搞,套用回溯模板。 var res [][]int func combinationSum(candidates []int, target int) [][]int { res = make([][]int, 0) 阅读全文
posted @ 2022-05-09 21:04 SoutherLea 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 46. 全排列 - 力扣(LeetCode) 思路 回溯法 var res [][]int func permute(nums []int) [][]int { res = make([][]int, 0) backTracking([]int{}, nums, len(nums)) return 阅读全文
posted @ 2022-05-09 20:27 SoutherLea 阅读(21) 评论(0) 推荐(0) 编辑