This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var directions = [4][2]int{{0, 1}, {0, -1}, {-1, 0}, {1, 0}} | |
func bfs(grid [][]int) { | |
var ( | |
queue [][]int | |
m = len(grid) | |
n = len(grid[0]) | |
) | |
for len(queue) > 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $graph = document.getElementById("graph"); | |
const pixelRatio = Math.ceil(window.devicePixelRatio); | |
const context = $graph.getContext("2d"); | |
const width = $graph.offsetWidth; | |
const height = $graph.offsetHeight; | |
$graph.height = height * pixelRatio; | |
$graph.width = width * pixelRatio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
if len(os.Args) < 2 || os.Args[1] != "client" { | |
for i := 0; i < 4; i++ { | |
go worker() | |
} | |
broker() | |
} else { | |
client() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type unionFind[]int | |
func (uf unionFind) find(i int) int { | |
if uf[i] != i { | |
uf[i] = uf.find(uf[i]) | |
} | |
return uf[i] | |
} | |
func (uf unionFind) union(x, y int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func worker(queue chan string, signal *sync.WaitGroup) { | |
for work := range queue { | |
} | |
signal.Done() | |
} | |
func main() { | |
count := runtime.NumCPU() - 1 | |
queue := make(chan string, 10) | |
signal := new(sync.WaitGroup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MinHeap []int | |
func (h MinHeap) Len() int { return len(h) } | |
func (h MinHeap) Less(i, j int) bool { return h[i] < h[j] } | |
func (h MinHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } | |
func (h *MinHeap) Push(x interface{}) { | |
*h = append(*h, x.(int)) | |
} | |
func (h *MinHeap) Pop() interface{} { | |
old := *h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func topoTraverse(n int, edge [][]int) { | |
graph := make(map[int][]int) | |
inTable := make([]int, n) | |
for _, edge := range edge { | |
graph[edge[0]] = append(graph[edge[0]], edge[1]) | |
inTable[edge[1]]++ | |
} | |
var queue []int | |
for i, v := range inTable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m := len(grid) | |
n := len(grid[0]) | |
for i := 0; i < m; i++ { | |
dfsClosedIsland(grid, i, 0) | |
dfsClosedIsland(grid, i, n-1) | |
} | |
for i := 0; i < n; i++ { | |
dfsClosedIsland(grid, 0, i) | |
dfsClosedIsland(grid, m-1, i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+build wireinject | |
package api | |
import ( | |
"github.com/google/wire" | |
"github.com/pot-code/go-producer/api/notification" | |
ut "github.com/pot-code/go-producer/api/notification/transport" | |
"github.com/pot-code/go-producer/pkg/db" | |
"github.com/pot-code/go-producer/pkg/uuid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn create next-app | |
npx create-next-app |
OlderNewer