当前位置:网站首页>go language study notes 2
go language study notes 2
2022-07-30 05:02:00 【N. LAWLIET】
Learn language with algorithms,
Go variable definitions can be
var s1 strings1 := "521"
Import and output need import "fmt"
fmt.Println("hello world")//Outputfmt.Scanf("%s%s", &s1, &s2)//input
The function uses func to define the parameter in front of the variable name, followed by the type, and the return value type is defined in front of the curly brackets
func test(s1 string, s2 string) int{return 1}
To get the length of the string, use strings.Count(str,"") to get it. The length should be reduced by one.
There is no char type in the go language, only the byte type, so a single character is of the byte type,
The array in the go language needs to initialize the length and cannot use variables, such as
var dp [10000][10000]int
That's all the language knowledge needed for the first algorithm problem,
Title: Given a string str and a string T, return the number of all substrings of str that contain all of T
Code
package mainimport ("fmt""math""strings")func main() {fmt.Println("hello world")var s1 stringvar s2 stringfmt.Scanf("%s%s", &s1, &s2)var ans int = findTsubString(s1, s2)fmt.Println("ans=", ans)//Findmain()strAns := getUniqueSubString("1232")fmt.Printf("strAns=%d", strAns)}func findTsubString(S string, T string) int {if strings.Count(S, "") < strings.Count(T, "") {return 0}N := strings.Count(S, "") - 1M := strings.Count(T, "") - 1var dp[10000][10000]intif S[0] == T[0] {dp[0][0] = 1}for index := 1; index < N; index++ {if S[index] == T[0] {dp[index][0] = dp[index-1][0] + 1} else {dp[index][0] = dp[index-1][0]}}for i := 1; i < N; i++ {for j := 1; j <= int(math.Min(float64(i), float64(M-1))); j++ {dp[i][j] = dp[i-1][j]if S[i] == T[j] {dp[i][j] += dp[i-1][j-1]}}}return dp[N-1][M-1]}
边栏推荐
- See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
- 四、Web开发
- 22. Why do you need a message queue?What are the advantages of using the message queue?
- VisualStudio2022 local debugging entry is particularly slow problem solving
- - B + tree index and MySQL series 】 【 what is the difference between a HASH index
- Solve the go environment can not compile exe
- Acwing完全数
- Compound Types--references, pointers
- The VUX Datetime component compute-days-function dynamically sets the date list
- Using the GPU parallel computing 】 【 OpenCL&OpenCLUtilty GPU parallel computing
猜你喜欢
Unity3D Application simulation enters the front and background and pauses
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
Discourse 自定义头部链接(Custom Header Links)
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
Image stitching (registration) case based on OpenCV
[MRCTF2020]Hello_ misc
解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
模拟问题(中)
Golang channel implementation principle
How with Mexico Volkswagen VW EDI connection to Mexico
随机推荐
How with Mexico Volkswagen VW EDI connection to Mexico
mysql isolation level
uni-app realizes cross-end development of mobile phone Bluetooth to receive and send data
Repetition XXL - JOB scheduling center background arbitrary command execution
Boss Rush (two-point answer + DP)
聊一聊什么是SaaS,以及遇到的问题......
L2-025 分而治之
Hexagon_V65_Programmers_Reference_Manual(11)
六、读取应用配置+日志配置
软件测试员必看!数据库知识mysql查询语句大全
(Hexagon_V65_Programmers_Reference_Manual(13)
05 Detailed explanation of the global configuration file application.properties
1. Get data - requests.get()
Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem
DAY17, CSRF vulnerability
需求设计文档和产品经理的角色改变
VisualStudio2022本地调试进入特别慢问题解决
Discourse 自定义头部链接(Custom Header Links)
字符串问题(下)
go语言学习笔记二