算法题
yyhero1
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
回溯法
//回溯法 //8*8的格子,每个颜色由1--5组成,给定任一一个格子,求出所有与格子相邻且颜色相同的格子的个数。 int map[8][8] = { {1,1,2,1,}, {1,1,2,1}, {1,2,1,2}, {1,1,1,1}, {1,1,2,1}, }; int dir[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } }; in...原创 2016-03-12 18:11:05 · 1575 阅读 · 0 评论 -
leetcode golang实现-----------------给出一个字符串,求出不重复的子字符串的最长长度
package main import ( "strings" ) /* 给出一个字符串,求出不重复的子字符串的最长长度 */ func lengthOfLongestSubstring(s string) int { if len(s) == 0 { return 0 } // 子字符串的头尾索引 i := 0 j := 1 // 最大长度 maxLen := 0...原创 2018-04-03 16:54:41 · 867 阅读 · 1 评论 -
leetcode golang实现 --------------- 实现一个数的整数次方 pow(x, n)
package main /* 实现一个数的整数次方 pow(x, n) */ func pow(x float64, n int) float64 { if x == 0 { return 0 } result := calPow(x, n) if n < 0 { result = 1 / result } return result } func calPo...原创 2018-04-03 16:57:15 · 5616 阅读 · 0 评论 -
leetcode golang实现 给入一个无序的数组,求出数组中两个元素和为m的下标
package main /* 给入一个无序的数组,求出数组中两个元素和为m的下标 */ func twoSum(array []int, sum int) (int, int, bool) { // 使用map存储对应下标的元素需要的另一半 tempMap := make(map[int]int) for i := 0; i < len(array); i++ { // ...原创 2018-04-03 16:58:29 · 518 阅读 · 0 评论 -
leetcode shuffle算法
// 原始的洗牌算法,遍历数组,每次随机一个,删除,再随机 // 时间复杂度O(n2) func shuffle(source []int) []int { result := make([]int, 0) for len(source) > 0 { j := rand.Intn(len(source)) result = append(result, source[j]) ...原创 2018-11-28 20:03:22 · 378 阅读 · 0 评论
分享