This file contains hidden or 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 findMaxConsecutiveOnes(nums []int) int { | |
total := 0 | |
max := 0 | |
for i := 0; i < len(nums); i++ { | |
if nums[i] == 1 { | |
total++ | |
if total > max { | |
max = total | |
} | |
} else { |
This file contains hidden or 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
// Slice implements sort.Interface | |
type Slice []int | |
func (a Slice) Len() int { return len(a) } | |
func (a Slice) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | |
func (a Slice) Less(i, j int) bool { return a[i] < a[j] } | |
func combine(n int, k int) [][]int { | |
a := []int{} | |
for i := 1; i <= n; i++ { |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"sort" | |
) | |
type Slice []int | |
func (a Slice) Len() int { return len(a) } |
This file contains hidden or 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
package main | |
import ( | |
"container/heap" | |
"fmt" | |
) | |
type mHeap struct { | |
value int | |
array int |
This file contains hidden or 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 threeSum(nums []int) [][]int { | |
result := [][]int{} | |
check := make(map[int]bool) | |
for i := 0; i < len(nums)-2; i++ { | |
if check[nums[i]] { | |
continue | |
} | |
for _, v := range twoSum(nums[i+1:], -nums[i]) { | |
if !(check[v[0]] || check[v[1]]) { | |
result = append(result, append(v, nums[i])) |
This file contains hidden or 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 maxDepth(root *TreeNode) int { | |
if root == nil { | |
return 0 | |
} | |
d := 1 + max(maxDepth(root.Right), maxDepth(root.Left)) | |
return d | |
} | |
func max(a, b int) int { | |
if a > b { |
This file contains hidden or 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() { | |
ipn := &net.IPNet{ | |
IP: net.IPv4(10,200,0,0), | |
Mask: net.CIDRMask(24, 32), | |
} | |
gw := calcGatewayIP(ipn) | |
fmt.Printf("%v", gw ) | |
} |
This file contains hidden or 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
#!/bin/bash | |
sudo apt-get update | |
sudo apt-get -y upgrade | |
sudo apt-get -y install make | |
curl -O https://storage.googleapis.com/golang/go1.12.6.linux-amd64.tar.gz | |
tar -xvf go1.12.6.linux-amd64.tar.gz | |
sudo mv go /usr/local | |
echo 'export PATH=$PATH:/usr/local/go/bin |
This file contains hidden or 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
// Client | |
conn, err := grpc.Dial(address, grpc.WithInsecure()) | |
if err != nil { | |
log.Fatalf("did not connect: %v", err) | |
} | |
defer conn.Close() | |
// Server | |
s := grpc.NewServer() | |
// ... register gRPC services ... |
This file contains hidden or 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
// Client | |
config := &tls.Config{ | |
InsecureSkipVerify: true, | |
} | |
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(credentials.NewTLS(config))) | |
if err != nil { | |
log.Fatalf("did not connect: %v", err) | |
} | |
defer conn.Close() |
OlderNewer