aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-12-19 06:44:41 +0000
committerterminaldweller <thabogre@gmail.com>2022-12-19 06:44:41 +0000
commit66f9ead6159155c5910183c191f1b7082bb56473 (patch)
tree312dfe6b982aaf01d27a8447500678da7e4d60fb
parent739 (diff)
downloadleetcode-66f9ead6159155c5910183c191f1b7082bb56473.tar.gz
leetcode-66f9ead6159155c5910183c191f1b7082bb56473.zip
update
-rw-r--r--1971/go.mod3
-rw-r--r--1971/main.go41
2 files changed, 44 insertions, 0 deletions
diff --git a/1971/go.mod b/1971/go.mod
new file mode 100644
index 0000000..5210a5a
--- /dev/null
+++ b/1971/go.mod
@@ -0,0 +1,3 @@
+module 1971
+
+go 1.19
diff --git a/1971/main.go b/1971/main.go
new file mode 100644
index 0000000..d7b025f
--- /dev/null
+++ b/1971/main.go
@@ -0,0 +1,41 @@
+package main
+
+import "fmt"
+
+func validPath(n int, edges [][]int, source int, destination int) bool {
+ seen := make([][]int, n)
+
+ for _, edge := range edges {
+ seen[edge[0]] = append(seen[edge[0]], edge[1])
+ seen[edge[1]] = append(seen[edge[1]], edge[0])
+ }
+
+ visited := map[int]struct{}{}
+ none := struct{}{}
+
+ q := []int{source}
+
+ for len(q) > 0 {
+ sz := len(q)
+
+ for i := 0; i < sz; i++ {
+ item := q[0]
+ if item == destination {
+ return true
+ }
+
+ if _, ok := visited[item]; !ok {
+ q = append(q, seen[item]...)
+ visited[item] = none
+ }
+ }
+
+ q = q[1:]
+ }
+
+ return false
+}
+
+func main() {
+ fmt.Println("vim-go")
+}