This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree | |
| /** | |
| * Definition for TreeNode. | |
| * type TreeNode struct { | |
| * Val int | |
| * Left *ListNode | |
| * Right *ListNode | |
| * } | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/kth-smallest-element-in-a-bst | |
| /** | |
| * Definition for a binary tree node. | |
| * type TreeNode struct { | |
| * Val int | |
| * Left *TreeNode | |
| * Right *TreeNode | |
| * } | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/majority-element-ii | |
| import "sort" | |
| func majorityElement(nums []int) []int { | |
| if len(nums) < 2 { | |
| return nums | |
| } | |
| sort.Ints(nums) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/summary-ranges | |
| func summaryRanges(nums []int) []string { | |
| numsLen := len(nums) | |
| if numsLen == 0 { | |
| return []string{} | |
| } | |
| ranges := []string{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/basic-calculator-ii | |
| import "strings" | |
| const ( | |
| space = rune(' ') | |
| plus = rune('+') | |
| minus = rune('-') | |
| divide = rune('/') | |
| asterisk = rune('*') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/maximal-square | |
| func maximalSquare(matrix [][]byte) int { | |
| n := len(matrix) | |
| if n == 0 { | |
| return 0 | |
| } | |
| m := len(matrix[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/combination-sum-iii | |
| func combinationSum3(k int, n int) [][]int { | |
| if k == 1 { | |
| return [][]int{{n}} | |
| } | |
| result := [][]int{} | |
| combination(1, k, n, []int{}, &result) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/kth-largest-element-in-an-array | |
| import "container/heap" | |
| type Heap []int | |
| func (h Heap) Swap(i, j int) { | |
| h[i], h[j] = h[j], h[i] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/house-robber-ii | |
| func rob(nums []int) int { | |
| n := len(nums) | |
| if n == 0 { | |
| return 0 | |
| } | |
| if n == 1 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| https://leetcode.com/problems/add-and-search-word-data-structure-design/ | |
| This solution based on the key idea of search engines: Inverted Index | |
| Please have a look at this https://nlp.stanford.edu/IR-book/html/htmledition/an-example-information-retrieval-problem-1.html | |
| Or take a look at this open source project https://github.com/suggest-go/suggest | |
| Briefly description: |