go实现剑指offer
https://www.nowcoder.com/exam/oj/ta?page=1&tpId=13&type=13
0830
JZ3 数组中重复的数字
思路一
将数字放到字典中,多了就加1,如果遇到大于1个数地,直接返回
https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
func duplicate(numbers []int) int {
// write code here
if numbers == nil {
return -1
}
dict := make(map[int]int)
for _, value := range numbers {
count := 1
if _, exist := dict[value]; exist {
dict[value]++
if dict[value] > 1 {
return value
}
} else {
dict[value] = count
}
}
return -1
}
JZ4 二维数组中的查找
https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/
func findNumberIn2DArray(matrix [][]int, target int) bool {
i, j := len(matrix)-1, 0
for i >= 0 && j < len(matrix[0]) {
if matrix[i][j] > target {
i -= 1
} else if matrix[i][j] < target {
j += 1
} else {
return true
}
}
return false
}
JZ42 连续子数组的最大和
https://leetcode.cn/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/
0831
https://leetcode.cn/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/
https://www.nowcoder.com/practice/11662ff51a714bbd8de809a89c481e21?tpId=13&tqId=2282583&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
https://leetcode.cn/problems/zui-xiao-de-kge-shu-lcof/