From 107ddd881dff24fbdda888e58858879b09544c21 Mon Sep 17 00:00:00 2001 From: ZGGSONG Date: Sat, 17 Dec 2022 15:11:00 +0800 Subject: [PATCH] backup --- LeetCode/Ex.2/main.go | 30 ++++++++++++++++++++++-------- go.mod | 3 +++ main.go | 5 +++++ map2/main.go | 23 +++++++++++++++++++++++ 4 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 go.mod create mode 100644 main.go create mode 100644 map2/main.go diff --git a/LeetCode/Ex.2/main.go b/LeetCode/Ex.2/main.go index c268973..e98a219 100644 --- a/LeetCode/Ex.2/main.go +++ b/LeetCode/Ex.2/main.go @@ -1,15 +1,12 @@ package main +import "fmt" + /** 给你两个非空 的链表,表示两个非负的整数。 它们每位数字都是按照逆序的方式存储的,并且每个节点只能存储一位数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外,这两个数都不会以 0开头。 */ -func main() { - -} - -//type ListNode /** * Definition for singly-linked list. @@ -18,6 +15,23 @@ func main() { * Next *ListNode * } */ -//func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { -// return nil -//} +type ListNode struct { + Val int + Next *ListNode +} + +func main() { + l1 := new(ListNode) + l2 := new(ListNode) + l1.Val = 0 + l2.Val = 2 + fmt.Println(addTwoNumbers(l1, l2)) +} + +func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { + + fmt.Printf("l1Val: %v\n", l1.Val) + fmt.Printf("l2Val: %v\n", l2.Val) + + return nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ba32114 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gostudy + +go 1.17 diff --git a/main.go b/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/map2/main.go b/map2/main.go new file mode 100644 index 0000000..ccc192f --- /dev/null +++ b/map2/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + words := "how do you do !" + splits := strings.Split(words, " ") + dictWords := make(map[string]int, 10) + for _, v := range splits { + _, ok := dictWords[v] + if !ok { + dictWords[v] = 1 + } else { + dictWords[v]++ + } + } + for k, v := range dictWords { + fmt.Printf("%v:%v\n", k, v) + } +}