当前位置:网站首页>2021-11-14:Fizz Buzz。 I'll give you an integer n and find the number from 1 to n
2021-11-14:Fizz Buzz。 I'll give you an integer n and find the number from 1 to n
2022-06-24 01:46:00 【Fuda scaffold constructor's daily question】
2021-11-14:Fizz Buzz. Give you an integer n , Find out from 1 To n Of each integer Fizz Buzz Express , And use string array answer( Subscript from 1 Start ) Return results , among :answeri == "FizzBuzz" If i At the same time 3 and 5 Multiple .answeri == "Fizz" If i yes 3 Multiple .answeri == "Buzz" If i yes 5 Multiple .answeri == i If none of the above conditions are met . Power button 412.
answer 2021-11-14:
Natural intelligence is enough . One traverse . branch 4 In this case :15 Multiple ,3 Multiple ,5 Multiple , Other situations .
Time complexity :O(N).
Extra space complexity :O(N). Results need to be saved .
The code to use golang To write . The code is as follows :
package main
import "fmt"
func main() {
ans := fizzBuzz(16)
fmt.Println(ans)
}
func fizzBuzz(n int) []string {
ans := make([]string, 0)
for i := 1; i <= n; i++ {
if i%15 == 0 {
ans = append(ans, "FizzBuzz")
} else if i%5 == 0 {
ans = append(ans, "Buzz")
} else if i%3 == 0 {
ans = append(ans, "Fizz")
} else {
ans = append(ans, fmt.Sprint(i))
}
}
return ans
}The results are as follows :
边栏推荐
- Property management source code based on wechat applet
- [dry goods] four tools linkage of automated batch hole digging process
- Location and troubleshooting of memory leakage: analysis of heap profiling principle
- Troubleshooting and repair of easygbs docking with universal video equipment to broadcast message 487
- [tcapulusdb knowledge base] common problems of tcapulusdb local deployment
- How to access the server through the fortress machine? What if the fortress cannot access the server?
- 什麼是養老理財?養老理財產品有哪些?
- How to build a high-quality website
- [tcapulusdb knowledge base] how to rebuild tables in tcapulusdb table management?
- Note 3 of disruptor: basic operation of ring queue (without disruptor class)
猜你喜欢
![[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)](/img/c8/f6c2a62b8ab8fa88bd2b3d8f35f592.jpg)
[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)

I, a 27 year old female programmer, feel that life is meaningless, not counting the accumulation fund deposit of 430000

It's too difficult for me. Ali has had 7 rounds of interviews (5 years of experience and won the offer of P7 post)
![[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)](/img/b5/a8c4bbaf868dd20b7dc9449d2a4378.jpg)
[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)
随机推荐
4-data persistence and shared interconnection
How to learn website construction does website construction need code
NFS file systems - mount and optimize
CLB O & M & operation best practices - big insight into access logs
Flink weapon: introduction to the open source platform streamx
How to realize court face recognition / flow statistics based on easycvr technology?
Behind the 1.6 trillion requests per day, the secret of DNSPod - state secret DOH
An error is reported when easynvr uploads the SSL certificate: the network request fails. How to handle it?
Can the server be restarted through the fortress machine? How are the fortress machines connected to the server
Echo framework: implementing service end flow limiting Middleware
Dart series: generics in dart classes
Gin framework: implementing distributed log tracing
SMS marketing is the key to retain customers
Tcapulusdb Jun · industry news collection (November 22)
How to build a high-quality website
Moment. JS how to get the zero hour time of the current time
[combat power upgrade] Tencent cloud's first arm architecture instance was launched! Experience the new architecture computing power!
How to build a practical website and how to operate after the website goes online
Location and troubleshooting of memory leakage: analysis of heap profiling principle
How to use the speech synthesis assistant? Does speech synthesis cost money?