forked from prabhudev740/pythonbatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.go
More file actions
139 lines (117 loc) · 2.31 KB
/
temp.go
File metadata and controls
139 lines (117 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// package main
// import (
// "fmt"
// // "math"
// // "sort"
// "strings"
// )
// func main() {
// // x := "1.1.1.1"
// // // x = strings.ReplaceAll(x, ".", "[.]")
// // x := []string{"please wait", "continue to fight", "continue to win"}
// // res := fimdMax(x)
// // fmt.Println(res)
// // temp()
// pattern2()
// }
// func sol(address string) string {
// var res string
// for _, v := range address {
// if v == '.' {
// res += "[.]"
// } else {
// res += string(v)
// }
// }
// return res
// }
// func fimdMax(sentences []string) int {
// res := 0
// for _, v := range sentences {
// c := len(strings.Split(v, " "))
// if res < c {
// res = c
// }
// }
// return res
// }
// func temp() {
// // res := strings.Join([]string{"a", "bc"}, "")
// // res := []int{}
// // strings.Contains()
// // fmt.Println(m, p, g)
// // if 10 && 10 {
// // fmt.Println("abv")
// // }
// x := 10
// y := 10
// z := y
// fmt.Println(&x, &y, &z)
// }
package main
import (
"fmt"
"math"
// "strconv"
)
func pattern2() {
n := 5
for i := 1; i <= n; i++ {
for j := n - i; j >= 1; j-- {
fmt.Printf(" ")
}
for j := i; j >= 1; j-- {
fmt.Printf("%d", j)
}
fmt.Println("")
}
}
func pattern() {
n := 5
for i := 1; i <= n; i++ {
for j := n - i; j >= 1; j-- {
fmt.Printf(" ")
}
for j := n - i + 1; j <= n; j++ {
fmt.Printf("%d", j)
}
fmt.Println("")
}
}
func main() {
// pattern()
// pattern2()
// arr := []int{1, 2, 3, 4, 5}
// index := 3
// fmt.Println(arr)
// arr = insert(arr, index, 600)
// fmt.Println(arr)
fmt.Println(isValid("([])"))
}
func insert(arr []int, pos, element int) []int {
arr = append(arr, element)
fmt.Println(arr)
for i := len(arr) - 1; i > pos; i-- {
arr[i], arr[i-1] = arr[i-1], arr[i]
fmt.Println(arr)
}
return arr
}
func isValid(s string) bool {
m := map[rune]rune{'}': '{', ']': '[', ')': '('}
temp := []rune{}
for _, v := range s {
if _, ok := m[v]; ok {
if len(temp) != 0 && m[v] == temp[len(temp)-1] {
fmt.Println(temp)
temp = temp[:len(temp)-1]
fmt.Println(temp)
} else {
return false
}
} else {
temp = append(temp, v)
}
}
return len(temp) == 0
}