Skip to content

Commit c39e7e5

Browse files
committed
update
1 parent f601013 commit c39e7e5

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

001xxx/143.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
func max(a, b int) int {
2+
if a <= b {
3+
return b
4+
}
5+
return a
6+
}
7+
8+
func longestCommonSubsequence(text1 string, text2 string) int {
9+
m, n := len(text1), len(text2)
10+
t := make([][]int, m+1)
11+
for i := 0; i <= m; i++ {
12+
t[i] = make([]int, n+1)
13+
}
14+
for i := 0; i < m; i++ {
15+
for j := 0; j < n; j++ {
16+
if text1[i] == text2[j] {
17+
t[i+1][j+1] = t[i][j] + 1
18+
} else {
19+
t[i+1][j+1] = max(t[i+1][j], t[i][j+1])
20+
}
21+
}
22+
}
23+
return t[m][n]
24+
}

001xxx/177.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
func cnt(i uint32) uint32 {
2+
i = (i & 0x55555555) + ((i >> 1) & 0x55555555)
3+
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
4+
i = (i & 0x0f0f0f0f) + ((i >> 4) & 0x0f0f0f0f)
5+
i = (i & 0x00ff00ff) + ((i >> 8) & 0x00ff00ff)
6+
i = (i & 0x0000ffff) + ((i >> 16) & 0x0000ffff)
7+
return i
8+
}
9+
10+
var ms = [100001]uint32{}
11+
12+
func canMakePaliQueries(s string, queries [][]int) []bool {
13+
o, l := make([]bool, len(queries)), len(s)
14+
var m uint32
15+
for i := 0; i < l; i++ {
16+
m ^= 1 << (s[i] - 'a')
17+
ms[i+1] = m
18+
}
19+
for i, q := range queries {
20+
o[i] = cnt(ms[q[0]]^ms[q[1]+1])>>1 <= uint32(q[2])
21+
}
22+
return o
23+
}

001xxx/184.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func distanceBetweenBusStops(distance []int, start int, destination int) int {
2+
if start > destination {
3+
start, destination = destination, start
4+
}
5+
s, s1 := 0, 0
6+
for i, d := range distance {
7+
s += d
8+
if i >= start && i < destination {
9+
s1 += d
10+
}
11+
}
12+
if s0 := s - s1; s0 < s1 {
13+
s1 = s0
14+
}
15+
return s1
16+
}

001xxx/185.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "time"
2+
3+
func dayOfTheWeek(day int, month int, year int) string {
4+
return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local).Weekday().String()
5+
}

001xxx/189.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
func maxNumberOfBalloons(text string) int {
2+
c1, c2, c3, c4, c5 := 0, 0, 0, 0, 0
3+
for i := 0; i < len(text); i++ {
4+
switch text[i] {
5+
case 'b':
6+
c1++
7+
case 'a':
8+
c2++
9+
case 'l':
10+
c3++
11+
case 'o':
12+
c4++
13+
case 'n':
14+
c5++
15+
}
16+
}
17+
c3, c4 = c3>>1, c4>>1
18+
o := c1
19+
if c2 < c1 {
20+
o = c2
21+
}
22+
if c3 < c2 {
23+
o = c3
24+
}
25+
if c4 < c3 {
26+
o = c4
27+
}
28+
if c5 < c4 {
29+
o = c5
30+
}
31+
return o
32+
}

001xxx/207.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func uniqueOccurrences(arr []int) bool {
2+
m := map[int]int{}
3+
for _, a := range arr {
4+
m[a]++
5+
}
6+
m1 := map[int]bool{}
7+
for _, c := range m {
8+
if m1[c] {
9+
return false
10+
}
11+
m1[c] = true
12+
}
13+
return true
14+
}

0 commit comments

Comments
 (0)