1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package helper
- import (
- "fmt"
- )
- // ListNode ...
- type ListNode struct {
- Val int
- Next *ListNode
- }
- // TreeNode ...
- type TreeNode struct {
- Val int
- Left *TreeNode
- Right *TreeNode
- }
- func abs(x int) int {
- if x < 0 {
- return -x
- }
- return x
- }
- func maxInt(x, y int) int {
- if x > y {
- return x
- }
- return y
- }
- func minInt(x, y int) int {
- if x < y {
- return x
- }
- return y
- }
- func list2str(head *ListNode) string {
- curr := head
- str := make([]rune, 0)
- for curr != nil {
- str = append(str, rune(curr.Val+'0'))
- curr = curr.Next
- }
- return string(str)
- }
- func printTree(root *TreeNode) {
- if root == nil {
- return
- }
- if root.Left != nil {
- printTree(root.Left)
- }
- if root.Right != nil {
- printTree(root.Right)
- }
- fmt.Print(root.Val, " ")
- }
|