Skip to content

Instantly share code, notes, and snippets.

View azihsoyn's full-sized avatar

Naoya Yoshizawa azihsoyn

View GitHub Profile
package main
import "fmt"
func main() {
fmt.Println(missingNumber([]int{3,0,1}))
}
func missingNumber(nums []int) int {
m := make(map[int]struct{}, len(nums))
var memo map[int]int
func init(){
memo = make(map[int]int)
memo[1] = 1
memo[2] = 2
}
func climbStairs(n int) int {
if v, ok := memo[n]; ok {
return v
func generate(numRows int) [][]int {
ret := make([][]int, numRows)
for i := 1; i <= numRows; i++ {
ret[i-1] = make([]int, i)
ret[i-1][0], ret[i-1][i-1] = 1, 1
for j := 2; j < i && j <= numRows-1; j++ {
ret[i-1][j-1] = ret[i-2][j-2] + ret[i-2][j-1]
}
}
return ret
@azihsoyn
azihsoyn / collection.go
Last active October 8, 2018 17:07
collection by contract
type List(type T) []T
func (l *List(T)) Filter(func(T) bool) *List(T)
func (l *List(T)) Map(func(T) T) *List(T)
func main(){
var l List{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
l.Filter(func(i int) bool {
@azihsoyn
azihsoyn / mapFunc.go
Created July 4, 2018 16:32
go collection map
package main
import (
"fmt"
"github.com/kr/pretty"
)
type IntList []int
version: 2
jobs:
build:
working_directory: /go/src/github.com/your_company/your_app
docker:
- image: circleci/golang:1.10.0
environment:
- GOCACHE: "/tmp/go/cache"
steps:
version: 2
jobs:
build:
working_directory: /go/src/github.com/your_company/your_app
docker:
- image: circleci/golang:1.10.0
environment:
- DEP_VERSION: 0.4.1
steps:
- run: git config --global url.ssh://[email protected]/your_company.insteadOf https://github.com/your_company
@azihsoyn
azihsoyn / circle.yml
Created March 23, 2018 12:43
example circleci 2.0 with go 1.10
version: 2
jobs:
build:
working_directory: /go/src/github.com/your_company/your_app
docker:
- image: circleci/golang:1.10.0
environment:
- GOCACHE: "/tmp/go/cache"
- DEP_VERSION: 0.4.1
steps:
@azihsoyn
azihsoyn / design.go
Last active April 4, 2017 08:00 — forked from ikawaha/design.go
KeyがEnumで制限されているHashOf
package design // The convention consists of naming the design
// package "design"
import (
. "github.com/goadesign/goa/design" // Use . imports to enable the DSL
. "github.com/goadesign/goa/design/apidsl"
)
var _ = API("cellar", func() { // API defines the microservice endpoint and
Title("The virtual wine cellar") // other global properties. There should be one
Description("A simple goa service") // and exactly one API definition appearing in
package main
import (
"reflect"
"testing"
)
func BenchmarkSetIntMap(b *testing.B) {
m := make(map[int]bool)
for i := 0; i < b.N; i++ {