add new solutions
This commit is contained in:
parent
ca24d0a56a
commit
0c73608ce5
36 changed files with 791 additions and 0 deletions
11
solutions/35/q3512/solution.go
Normal file
11
solutions/35/q3512/solution.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package q3512
|
||||
|
||||
func minOperations(nums []int, k int) int {
|
||||
sum := 0
|
||||
for i := range nums {
|
||||
sum += nums[i]
|
||||
}
|
||||
return sum % k
|
||||
}
|
||||
|
||||
var _ = minOperations
|
||||
21
solutions/35/q3516/solution.go
Normal file
21
solutions/35/q3516/solution.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package q3516
|
||||
|
||||
func abs(n int) int {
|
||||
if n < 0 {
|
||||
return -n
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func findClosest(x int, y int, z int) int {
|
||||
d1, d2 := abs(x-z), abs(y-z)
|
||||
switch {
|
||||
case d1 == d2:
|
||||
return 0
|
||||
case d1 < d2:
|
||||
return 1
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
var _ = findClosest
|
||||
22
solutions/35/q3541/solution.go
Normal file
22
solutions/35/q3541/solution.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package q3541
|
||||
|
||||
func maxFreqSum(s string) int {
|
||||
freqs := [26]int{}
|
||||
for i := range len(s) {
|
||||
freqs[s[i]-'a']++
|
||||
}
|
||||
|
||||
max1, max2 := 0, 0
|
||||
for i, freq := range freqs {
|
||||
c := byte(i + 'a')
|
||||
switch c {
|
||||
case 'a', 'e', 'i', 'o', 'u':
|
||||
max1 = max(max1, freq)
|
||||
default:
|
||||
max2 = max(max2, freq)
|
||||
}
|
||||
}
|
||||
return max1 + max2
|
||||
}
|
||||
|
||||
var _ = maxFreqSum
|
||||
Loading…
Add table
Add a link
Reference in a new issue