p1

package
v0.0.0-...-eb8a366 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: Unlicense Imports: 6 Imported by: 0

Documentation

Overview

Package p1 LeetCode 0013 Roman to Integer Latin number to integer

Example (RotateRight)

Test rotateRight

list := new(ListNode)

head := list
list.Val = 1
list.Next = new(ListNode)
current := list.Next
current.Val = 2
current.Next = new(ListNode)
current = current.Next
current.Val = 3
current.Next = new(ListNode)
current = current.Next
current.Val = 4
current.Next = new(ListNode)
current = current.Next
current.Val = 5

current = head

// for current != nil {
// 	fmt.Println(current.Val)
// 	current = current.Next
// }

// fmt.Printf("%#v\n", head)
current = rotateRight(head, 2)
// fmt.Printf("%#v\n", current)

for current != nil {
	fmt.Println(current.Val)
	current = current.Next
}
Output:

4
5
1
2
3
Example (TreeTest)
treeTest()
Output:

BTree
    0
1
    2
3
    4

[0 1 2 3 4] [0 -10 5 -3 9]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountOdds

func CountOdds(low int, high int) int

CountOdds count odd number in range

Example
fmt.Println(CountOdds(3, 7))
Output:

3

func FizzBuzz

func FizzBuzz(n int) (result []string)

FizzBuzz 3=Fizz 5=Buzz 15=FizzBuzz

Given an integer n, return a string array answer (1-indexed) where: answer[i] == "FizzBuzz" if i is divisible by 3 and 5. answer[i] == "Fizz" if i is divisible by 3. answer[i] == "Buzz" if i is divisible by 5. answer[i] == i (as a string) if none of the above conditions are true.

func IntPow

func IntPow(n, m int) int

IntPow calculates n to the mth power. Since the result is an int, it is assumed that m is a positive power

func IsPlaindromeInt

func IsPlaindromeInt(x int) bool

IsPlaindromeInt true if a integer is a palindrome 121==true

Example
inp := 121
fmt.Println(IsPlaindromeInt(inp))
Output:

true

func LongestCommonPrefix

func LongestCommonPrefix(strs []string) string

LongestCommonPrefix return prefix used in all string

Example
strs := []string{"flower", "flower", "flower", "flower"}
fmt.Println(LongestCommonPrefix(strs))
Output:

flower

func RomanToInt

func RomanToInt(s string) int

RomanToInt convert roman number to int

Example
inp := "MCDLXXVI"
fmt.Println(RomanToInt(inp))
Output:

1476

Types

type ListNode

type ListNode struct {
	Val  int
	Next *ListNode
}

ListNode definition for singly-linked list

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL