当前位置:网站首页>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 :
边栏推荐
- Batch generation of 2D codes from txt files
- Istio practice manual | meeting the new generation of microservice architecture
- [software cost consulting] information project bidding process and precautions
- How does smart digital operation get through offline collection and online marketing?
- [official time limit activity] in November, if you dare to write, you will get a prize
- How to self-study website construction is website construction company reliable
- EasyPlayer. JS play m3u8 error net:: err_ EMPTY_ Response, how to solve it?
- An error is reported when easynvr uploads the SSL certificate: the network request fails. How to handle it?
- Video stream playback address redirection optimization after easycvr replaces the new kernel
- [tcapulusdb knowledge base] how to clean up tables in tcapulusdb table management?
猜你喜欢
![[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)
随机推荐
Railway patrol system - Railway Intelligent Patrol communication system
[tcapulusdb knowledge base] how to clean up tables in tcapulusdb table management?
How to use the speech synthesis assistant? Does speech synthesis cost money?
Gin framework: implementing distributed log tracing
Netease Shufan: Data productivity platform 2.0 promotes "everyone uses data and always uses data"
Oracle sqlldr quick import and sqluldr2 quick export
Ppt layout design how to make pages not messy
SAP mm maintains inter company sto error -no delivery type defined for supplying
CLB O & M & operation best practices - big insight into access logs
[technical grass planting] cdn+ lightweight server +hugo= let the blog "cloud native"
Intensive use of glusterfs 4.1
What is function point analysis - FPA
Go language core 36 lectures (go language practice and application VII) -- learning notes
Moment. JS how to use epoch time to construct objects
Note sharing (5) -precautions for Oracle to MySQL
Introduction to easycvr interfacing with Huawei IVS subscription camera and user change request interface
What is the website domain name trademark registration process? What is the use of a website domain name trademark?
8、 Pipeline pipeline construction project
How does easynvr set the video recording to be saved for more than 30 days?
How does smart digital operation get through offline collection and online marketing?