Skip to content

Instantly share code, notes, and snippets.

View alldroll's full-sized avatar

Aleksandr Petrov alldroll

View GitHub Profile
@alldroll
alldroll / solution.go
Last active December 6, 2019 15:23
Find the Closest Palindrome
// https://leetcode.com/problems/find-the-closest-palindrome/submissions/
import (
"strconv"
"strings"
)
const (
zero = byte('0')
nine = byte('9')
@alldroll
alldroll / .go
Last active January 21, 2020 15:14
Regular Expression Matching
func isMatch(s string, p string) bool {
n, m := len(s), len(p)
dp := make([][]bool, n+1)
for i := n; i >= 0; i-- {
dp[i] = make([]bool, m+1)
}
dp[n][m] = true
// https://leetcode.com/problems/unique-binary-search-trees-ii/
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/unique-binary-search-trees-ii
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/unique-binary-search-trees
func numTrees(n int) int {
if n == 0 {
return 1
}
memorized := make([][]int, n + 2)
for i, _ := range memorized {
// https://leetcode.com/problems/validate-binary-search-tree
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/binary-tree-level-order-traversal
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// https://leetcode.com/problems/path-sum-ii
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
// 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) {