You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
837 B

3 years ago
package main
import (
"fmt"
"strconv"
)
func main() {
// 时间复杂度=o(1)
fmt.Println("1 Hello World!")
// 时间复杂度=o(n)
for i, n := 0, 100; i < n; i++ {
fmt.Println(strconv.Itoa(i), " Hello World!")
}
// 时间复杂度=o(n)
for i, n, m := 0, 100, 10; i < n; i++ {
for j := 0; j < m; j++ {
fmt.Println(strconv.Itoa(i), strconv.Itoa(j), " Hello World!")
}
}
// 时间复杂度=o(1)
fmt.Println("1 Hello World!")
fmt.Println("2 Hello World!")
fmt.Println("3 Hello World!")
// 时间复杂度=o(n<sup>2</sup>)
for i, n, m := 0, 100, 10; i < n; i++ {
fmt.Println(strconv.Itoa(i), " Hello World!")
for j := 0; j < m; j++ {
fmt.Println(strconv.Itoa(j), " Hello World!")
}
}
// 时间复杂度=o(log n)
n := 100
for n > 1 {
fmt.Println(strconv.Itoa(n), " Hello World!")
n /= 2
}
}