Skip to content

Commit 57bb43e

Browse files
committed
shopee春招笔试
1 parent 5f9a74e commit 57bb43e

File tree

10 files changed

+285
-0
lines changed

10 files changed

+285
-0
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @lc app=leetcode.cn id=121 lang=golang
3+
*
4+
* [121] 买卖股票的最佳时机
5+
*/
6+
7+
// @lc code=start
8+
func maxProfit(prices []int) int {
9+
if len(prices) < 2 {
10+
return 0
11+
}
12+
min := prices[0]
13+
max := 0
14+
for i := 1; i < len(prices); i++ {
15+
tmp := prices[i]
16+
if tmp < min {
17+
min = tmp
18+
continue
19+
}
20+
if max < tmp-min {
21+
max = tmp - min
22+
}
23+
}
24+
return max
25+
}
26+
27+
// @lc code=end
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @lc app=leetcode.cn id=122 lang=golang
3+
*
4+
* [122] 买卖股票的最佳时机 II
5+
*/
6+
7+
// @lc code=start
8+
func maxProfit(prices []int) int {
9+
sum := 0
10+
for i := 0; i < len(prices)-1; i++ {
11+
if prices[i+1] > prices[i] {
12+
sum += prices[i+1] - prices[i]
13+
}
14+
}
15+
return sum
16+
}
17+
18+
// @lc code=end
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @lc app=leetcode.cn id=123 lang=golang
3+
*
4+
* [123] 买卖股票的最佳时机 III
5+
*/
6+
package leetcode
7+
8+
import "math"
9+
10+
// @lc code=start
11+
func maxProfit(prices []int) int {
12+
if len(prices) < 2 {
13+
return 0
14+
}
15+
dp_i10, dp_i11, dp_i20, dp_i21 := 0, math.MinInt64, 0, math.MinInt64
16+
for _, v := range prices {
17+
dp_i10 = max(dp_i10, dp_i11+v)
18+
dp_i11 = max(dp_i11, -v)
19+
dp_i20 = max(dp_i20, dp_i21+v)
20+
dp_i21 = max(dp_i21, dp_i10-v)
21+
22+
}
23+
return dp_i20
24+
}
25+
26+
func max(a, b int) int {
27+
if b > a {
28+
a = b
29+
}
30+
return a
31+
}
32+
33+
// @lc code=end
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* @lc app=leetcode.cn id=680 lang=golang
3+
*
4+
* [680] 验证回文字符串 Ⅱ
5+
*/
6+
package leetcode
7+
8+
import "fmt"
9+
10+
// @lc code=start
11+
func validPalindrome(s string) bool {
12+
if is(s) {
13+
return true
14+
}
15+
for i := 0; i < len(s); i++ {
16+
tmp := s[:i] + s[i+1:]
17+
fmt.Println(tmp)
18+
if is(tmp) {
19+
return true
20+
}
21+
}
22+
return false
23+
}
24+
25+
func is(s string) bool {
26+
i, j := 0, len(s)-1
27+
for i <= j {
28+
if s[i] != s[j] {
29+
return false
30+
}
31+
i++
32+
j--
33+
}
34+
return true
35+
}
36+
37+
// @lc code=end

Diff for: 笔面试题/shopee春招/不同走法/solution.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
var n, m int
9+
fmt.Scan(&m, &n)
10+
result := make([][]uint64, n)
11+
tmp := make([]uint64, m)
12+
for j := 0; j < m; j++ {
13+
tmp[j] = 1
14+
}
15+
result[0] = tmp
16+
for i := 1; i < n; i++ {
17+
tmp := make([]uint64, m)
18+
tmp[0] = 1
19+
for j := 1; j < m; j++ {
20+
tmp[j] = tmp[j-1] + result[i-1][j]
21+
22+
}
23+
result[i] = tmp
24+
}
25+
fmt.Println(result[n-1][m-1])
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
)
9+
10+
func main() {
11+
reader := bufio.NewReader(os.Stdin)
12+
bytes, _, _ := reader.ReadLine()
13+
str := string(bytes)
14+
15+
now := []int{}
16+
start := 0
17+
for i := range str {
18+
if str[i] == ' ' {
19+
num, _ := strconv.Atoi(str[start:i])
20+
now = append(now, num)
21+
start = i + 1
22+
}
23+
}
24+
num, _ := strconv.Atoi(str[start:])
25+
now = append(now, num)
26+
27+
solve(now)
28+
}
29+
30+
func solve(now []int) {
31+
start, end := 0, 0
32+
l := 0
33+
//fmt.Println(now)
34+
for i := 0; i < len(now); i++ {
35+
if end == now[i] {
36+
if start < end {
37+
l++
38+
start++
39+
}
40+
} else {
41+
end = now[i]
42+
start = 1
43+
l++
44+
}
45+
// fmt.Println(start, end, l, now[i])
46+
}
47+
fmt.Println(l)
48+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
)
7+
8+
func main() {
9+
var s1, s2 string
10+
fmt.Scan(&s1, &s2)
11+
fmt.Println(solve(s1, s2))
12+
}
13+
14+
func solve(str1, str2 string) int {
15+
s1, s2 := getArr(str1), getArr(str2)
16+
for i := 0; i < len(s1) && i < len(s2); i++ {
17+
if s1[i] > s2[i] {
18+
return 1
19+
} else if s1[i] < s2[i] {
20+
return -1
21+
}
22+
}
23+
return 0
24+
}
25+
26+
func getArr(str string) []int {
27+
arr := []int{}
28+
start := 0
29+
for i := range str {
30+
if str[i] == '.' || str[i] == ',' {
31+
num, _ := strconv.Atoi(str[start:i])
32+
arr = append(arr, num)
33+
start = i + 1
34+
}
35+
}
36+
num, _ := strconv.Atoi(str[start:])
37+
return append(arr, num)
38+
}

Diff for: 笔面试题/星辰天合/sql.sql

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
user
2+
id
3+
name
4+
person_id
5+
6+
person
7+
id
8+
name
9+
10+
person_auth
11+
id
12+
person_id
13+
auth_id
14+
15+
auth
16+
id
17+
name
18+
19+
auth_do
20+
id
21+
auth_id
22+
do_id
23+
24+
do
25+
id
26+
name
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println(solve([]string{"aa", "bb", "cc", "dd", "eeee"}, 2))
7+
}
8+
9+
func solve(arr []string, flag int) [][]string {
10+
result := [][]string{}
11+
j := 1
12+
tmp := []string{}
13+
for i := 0; i < len(arr); i++ {
14+
if j < flag {
15+
tmp = append(tmp, arr[i])
16+
j++
17+
} else if j == flag {
18+
tmp = append(tmp, arr[i])
19+
result = append(result, tmp)
20+
j = 1
21+
tmp = []string{}
22+
}
23+
}
24+
if j != 1 {
25+
result = append(result, tmp)
26+
}
27+
return result
28+
}
29+
30+
// 用户,角色,每个角色权限,权限对应功能

0 commit comments

Comments
 (0)