feat:完善入驻信息管理

This commit is contained in:
henry
2021-12-02 15:23:48 +08:00
parent 30173f8dd2
commit 5c4d883c97
12 changed files with 418 additions and 203 deletions

109
utils/code_test.go Normal file
View File

@ -0,0 +1,109 @@
package utils
import (
"fmt"
"sort"
"testing"
)
var rank = []string{
"Gold Medal", "Silver Medal", "Bronze Medal",
}
type Score struct {
Score int
Index int
}
func findRelativeRanks(score []int) []string {
length := len(score)
scores := make([]*Score, length)
for k, v := range score {
scores[k] = &Score{
Score: v,
Index: k,
}
}
sort.Slice(scores, func(i, j int) bool {
return scores[i].Score > scores[j].Score
})
out := make([]string, length)
for k, v := range scores {
if k < 3 {
out[v.Index] = rank[k]
continue
}
out[v.Index] = fmt.Sprintf("%d", k+1)
}
return out
}
func twoSum(nums []int, target int) []int {
length := len(nums)
for i := 0; i < length; i++ {
for j := i + 1; j < length; j++ {
if nums[i]+nums[j] == target {
return []int{i, j}
}
}
}
return []int{}
}
type ListNode struct {
Val int
Next *ListNode
}
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
out := new(ListNode)
if l1 != nil || l2 != nil {
}
return out
}
func lengthOfLongestSubstring(s string) int {
arrs := make([]map[rune]int, 0)
_runes := []rune(s)
_map := make(map[rune]int, 0)
length := len(_runes)
for k, v := range _runes {
if _, has := _map[v]; !has {
_map[v] = 1
if k >= length-1 {
goto CONTINUE
}
continue
}
CONTINUE:
arrs = append(arrs, _map)
fmt.Println(_map)
_map = map[rune]int{v: 1}
}
out := 0
for _, v := range arrs {
_length := len(v)
if out != _length && _length > out {
out = _length
}
}
return out
}
func TestCode(t *testing.T) {
//src := []int{5, 4, 3, 2, 1}
//t.Log(findRelativeRanks(src))
//t.Log(twoSum([]int{3, 2, 4}, 6))
t.Log(lengthOfLongestSubstring("dvdf"))
}

View File

@ -3,6 +3,8 @@ package utils
import "testing"
func TestToSnake(t *testing.T) {
src := "sys_"
t.Log(ToSnake(src, "_"))
src := []int{1, 2, 3, 4, 5, 6}
t.Log(src)
ReverseSlice(src)
t.Log(src)
}

8
utils/utils.go Normal file
View File

@ -0,0 +1,8 @@
package utils
func ReverseSlice(src []int) []int {
for from, to := 0, len(src)-1; from < to; from, to = from+1, to-1 {
src[from], src[to] = src[to], src[from]
}
return src
}