Skip to content

Commit

Permalink
初始化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
fengdou902 committed Oct 10, 2021
1 parent ccc1b67 commit f71b776
Show file tree
Hide file tree
Showing 134 changed files with 7,753 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/devtest.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions atomic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {

}
52 changes: 52 additions & 0 deletions basic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
@Time : 2020/10/13 07:39
@Author : ZhaoJunfeng
@File : basic
*/
package main

import (
"fmt"
"math"
"math/cmplx"
)

func main() {
euler()
}

//常量
func enums() {
const(
cpp=iota
_
python
golang
javascript
)
fmt.Println(cpp,python,golang,javascript)

//b,kb,mb,gb,tb,pb
const (
b=1<<(10*iota)
kb
mb
gb
tb
pb
)
fmt.Println(b,kb,mb,gb,tb,pb)
}

func euler() {
c:=3+4i
fmt.Println(cmplx.Abs(c))

fmt.Printf("%.3f\n",
cmplx.Exp(1i*math.Pi+1),
//cmplx.Pow(math.E,1i*math.Pi)+1
)

//枚举
enums()
}
66 changes: 66 additions & 0 deletions basic/arr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
@Time : 2021/4/7 19:08
@Author : ZhaoJunfeng
@File : arr_test
*/
package basic

import (
"fmt"
"testing"
)

func TestTwoSum(t *testing.T) {
tests := []struct {
name string
arr []int
target int
wantData []int
}{
{"twoSum", []int{3, 2, 4}, 6, []int{1, 2}},
}

for _, test := range tests {
ret := twoSum(test.arr, test.target)
fmt.Printf("test.arr:%v\n", ret)
}

defer fmt.Printf("defer1\n")
defer fmt.Printf("defer2\n")
defer fmt.Printf("defer3\n")
}

func twoSum(nums []int, target int) []int {
var ret = make([]int, 0, 2)
tmpMap := make(map[int]int)
for i := range nums {
tmpMap[nums[i]] = i
}

for j := range nums {
a := nums[j]
if a > target {
continue
}
b := target - a
if v, ok := tmpMap[b]; ok {
ret = append(ret, j, v)
return ret
}
}
return ret
}

func TestFindUniqInt(t *testing.T) {
ret := tArr([]int{1, 2, 1, 2, 3,3,5})
fmt.Printf("%d\n", ret)
}

// []int{1,1,2}
func tArr(arr []int) int {
var ret int
for _, v := range arr {
ret ^= v
}
return ret
}
11 changes: 11 additions & 0 deletions basic/bloomFilter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
@Time : 2021/3/18 13:40
@Author : ZhaoJunfeng
@File : bloomFilter
布隆过滤器
特征:某元素一定不存在或者可能存在
1.如果这个元素不在,就一定不在
2.如果这个元素在,再到缓存
*/
package basic

51 changes: 51 additions & 0 deletions basic/bubbleSort_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
@Time : 2021/3/26 17:13
@Author : ZhaoJunfeng
@File : bubbleSort_test
*/
package basic

import (
"fmt"
"testing"
"time"
)

func TestBubbleSort(t *testing.T) {
arr := generateRandomNumber(0, 99999, 99999)
start := time.Now()
// arr := []int{3, 4, 2, 6, 8, 0, 1, 5, 7, 9}
bubbleSort(arr)
// insertionSort(arr)
latency := time.Since(start)
fmt.Printf("bubbleSort time cost:%vs\n", latency.Seconds())
// fmt.Printf("bubbleSort arr:%v\n", arr)
}

func bubbleSort(arr []int) {
if len(arr) == 0 {
return
}
l := len(arr)
for i := 0; i < l; i++ {
for j := 0; j < l-1-i; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
}

// 插入排序
func insertionSort(arr []int) []int {
for i:= range arr {
preIndex:=i-1
current := arr[i]
for preIndex >= 0 && arr[preIndex] > current {
arr[preIndex+1] = arr[preIndex]
preIndex -=1
}
arr[preIndex+1] = current
}
return arr
}
Binary file added basic/command-line-arguments
Binary file not shown.
48 changes: 48 additions & 0 deletions basic/dp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
@Time : 2021/4/16 10:05
@Author : ZhaoJunfeng
@File : dp_test
*/
package basic

import (
"math"
"testing"
)

func TestCoinChange(t *testing.T) {
tests := []struct {
coins []int
amount int
}{
{[]int{1,2,5},11},
{[]int{2},3},
{[]int{1},0},
}
for _, test := range tests {
ret := coinChange(test.coins, test.amount)
t.Logf("coinChange result:%v\n", ret)
}
}

func coinChange(coins []int, amount int) int {
if len(coins) == 0 {
return -1
}
var dp = make([]int, amount+1)
dp[0] = 0
for i := 1; i <= amount; i++ {
var min = math.MaxInt64
for j := 0; j < len(coins); j++ {
// 所有小于等于i的面值coins[j],并且最优解小于默认最大值
if coins[j] <=i && dp[i-coins[j]] < min {
min = dp[i-coins[j]] + 1 // 更新dp
}
}
dp[i] = min
}
if dp[amount] == math.MaxInt64 {
return -1
}
return dp[amount]
}
63 changes: 63 additions & 0 deletions basic/fibonacci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
@Time : 2021/4/12 18:21
@Author : ZhaoJunfeng
@File : fibonaqi_test
*/
package basic

import (
"fmt"
"testing"
)

var count int

func TestFibonacci(t *testing.T) {
tests := []struct {
name string
method uint8 // 1:递归,2:正推
n int
}{
{name: "递归法", method: 1, n: 10},
{name: "正推法", method: 2, n: 10},
}

for _, test := range tests {
var ret int
switch test.method {
case 1:
ret = Fibonacci(test.n)
case 2:
ret = Fibonacci2(test.n)
}

fmt.Printf("%v:%v\n", test.name, ret)
}

}

var rest = make(map[int]int)

// 递归
func Fibonacci(n int) int {
if ret, ok := rest[n]; ok {
return ret
}
if n == 0 {
return 0
}
if n == 1 {
return 1
}
return Fibonacci(n-1) + Fibonacci(n-2)
}

func Fibonacci2(n int) int {
var arr = make([]int, n+1)
arr[0] = 0
arr[1] = 1
for i := 2; i <= n; i++ {
arr[i] = arr[i-1] + arr[i-2]
}
return arr[n]
}
Loading

0 comments on commit f71b776

Please sign in to comment.