当前位置:网站首页>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)//inputThe 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]intThat'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]}边栏推荐
- 5. View parsing and template engine
- Notes on "The Law of Construction"---Chapter 10 Typical Users and Scenarios
- LeetCode Algorithm 328. 奇偶链表
- file system two
- Chapter8 Support Vector Machines
- gnss rtcm rtklib Ntrip...
- 软件测试员必看!数据库知识mysql查询语句大全
- 小程序使用npm包定制全局样式
- Six, read application configuration + log configuration
- Hexagon_V65_Programmers_Reference_Manual(10)
猜你喜欢

三、依赖配置管理

Image stitching (registration) case based on OpenCV

Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction

IGBT wafers used in photovoltaic inverters

KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!

Simulation problem (middle)

Web page element parsing a tag

See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices

小程序使用npm包定制全局样式

Hexagon_V65_Programmers_Reference_Manual(11)
随机推荐
[Redis Master Cultivation Road] Jedis - the basic use of Jedis
C# One Week Introductory "C# - Classes and Objects" Day Six
Dynamically bind href url
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
Verify that the addShutdownHook hook takes effect
小程序使用npm包定制全局样式
五、视图解析与模板引擎
【MySQL系列】-B+树索引和HASH索引有什么区别
WPF study notes "WPF Layout Basics"
SVN View Username and Password
[MRCTF2020]Hello_misc
Let's talk about what SaaS is, and the problems encountered...
go语言学习笔记二
模拟问题(上)
字符串问题(上)
webService interface
2.6 Merge Sort
Mini Program wx.miniProgram.navigateTo jump address cannot be tabbar address
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
斐波那契数列的递归优化《备忘录递归》