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() { | |
srcSlice := []int{1, 2, 3} | |
anotherSlice := srcSlice[:3] | |
for i := 0; i < 3; i++ { | |
srcSlice[i] += 10 | |
} | |
fmt.Println(srcSlice) | |
fmt.Println(anotherSlice) | |
} |
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() { | |
s := []int{1, 2, 3} | |
p := s[:3] | |
for i := 0; i < 3; i++ { | |
s[i] += 10 | |
} | |
fmt.Println(s) | |
fmt.Println(p) | |
} |
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
input = [ | |
[1, 0, 0, 0, 256, "AU-8a888ca7567d"], | |
[1, 0, 1, 0, 256, "CN-8173da22ea8b"], | |
[1, 0, 2, 0, 512, "CN-8173da22ea8b"], | |
[1, 0, 4, 0, 1024, "AU-4d44a4952b26"], | |
[1, 0, 8, 0, 2048, "CN-cc1064bf6999"], | |
[1, 0, 16, 0, 4096, "JP-9413fa3d189a"], | |
[1, 0, 32, 0, 8192, "CN-cc1064bf6999"] | |
] |
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 getRequiredCarsNum2(busCap, carCap int, stations []int) int { | |
cars := 0 | |
busUsed := false | |
resortFullBus := -1 | |
resortHalfBus := -1 | |
halfBusMax := 0 | |
for i, p := range stations { | |
// Don't care about empty stations | |
if p == 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
// Flatten integers array | |
// | |
// This simple utility flattens an arbitrarily nested array of integers. | |
// Example: [[1,2,[3]],4] -> [1,2,3,4] | |
// | |
// Example usage: | |
// $ ./flatten '[1,2,[4,5,[6],12],14]' | |
// [1 2 4 5 6 12 14] | |
// | |
// If no argument is provided, an example data is used: [[1,2,[3]],4] |