Skip to content

Instantly share code, notes, and snippets.

// https://leetcode.com/problems/flatten-binary-tree-to-linked-list
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func flatten(root *TreeNode) {
// https://leetcode.com/problems/triangle/
func minimumTotal(triangle [][]int) int {
if len(triangle) == 0 {
return 0
}
height := len(triangle)
width := len(triangle[height - 1])
memorized := make([]int, width)
// https://leetcode.com/problems/sum-root-to-leaf-numbers
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/palindrome-partitioning
type pair struct {
left, right int
}
func partition(s string) [][]string {
chars := []rune(s)
ch := make(chan pair)
transitionTable := make([][]int, len(chars))
// https://leetcode.com/problems/word-break
func wordBreak(s string, wordDict []string) bool {
wordMap := make(map[string]struct{}, len(wordDict))
for _, word := range wordDict {
wordMap[word] = struct{}{}
}
chars := []rune(s)
// https://leetcode.com/problems/linked-list-cycle-ii/ccccccccc
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func detectCycle(head *ListNode) *ListNode {
// https://leetcode.com/problems/reorder-list
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reorderList(head *ListNode) {
// https://leetcode.com/problems/binary-tree-preorder-traversal
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/lru-cache
type LRUCache struct {
cache map[int]*listNode
head *listNode
tail *listNode
capacity int
}
type listNode struct {
// https://leetcode.com/problems/sort-list
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func sortList(head *ListNode) *ListNode {