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
Decimal | Binary | Num of 1s | |
---|---|---|---|
0 | 0 | 0 | |
1 | 01 | 1 | |
2 | 10 | 1 | |
3 | 11 | 2 | |
4 | 100 | 1 | |
5 | 101 | 2 | |
6 | 110 | 2 | |
7 | 111 | 3 | |
8 | 1000 | 1 |
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
Decimal | Binary | Num of 1s | |
---|---|---|---|
0 | 0 | 0 | |
1 | 01 | 1 | |
2 | 10 | 1 | |
3 | 11 | 2 | |
4 | 100 | 1 | |
5 | 101 | 2 |
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 countBits(num int) []int { | |
results := make([]int, num+1) | |
bitsMap := []int{0, 1, 1, 2} | |
base := 4 | |
for i := 0; i < 4; i++ { | |
if i > num { | |
return results | |
} |
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 removeElement(nums []int, val int) int { | |
n := 0 | |
for i, num := range nums { | |
if num != val { | |
nums[n] = nums[i] | |
n++ | |
} | |
} | |
return n | |
} |
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 longestCommonPrefix(strs []string) string { | |
prefix := "" | |
if len(strs) == 0 { | |
return prefix | |
} | |
i := 0 | |
for { |
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 romanToInt(s string) int { | |
sum := 0 | |
var prev string | |
for i := len(s) - 1; i >= 0; i-- { | |
c := string(s[i]) | |
switch c { | |
case "I": | |
if prev == "V" || prev == "X" { | |
sum -= 1 |
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 checkPossibility(nums []int) bool { | |
const MaxUint = ^uint(0) | |
const MaxInt = int(MaxUint >> 1) | |
const MinInt = -MaxInt - 1 | |
chance := true | |
max := MinInt | |
for i := 0; i < len(nums)-1; i++ { | |
if nums[i] > nums[i+1] { | |
if chance { |
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 MyLinkedList struct { | |
head *Node | |
} | |
type Node struct { | |
next *Node | |
val 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
# Docker connect to host machine: | |
1. Use `--net="host"` in docker `run` command, then connet with `127.0.0.1` | |
2. Use: `host.docker.internal` | |
# Docker's localhost IP: | |
172.17.0.1 | |
# Run docker in interactive Bash session | |
$ docker run -it <image> /bin/bash |
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 first = new Promise((resolve, reject) => { | |
setTimeout(() => resolve("first"), 1000); | |
}); | |
const second = new Promise((resolve, reject) => { | |
setTimeout(() => reject("second error"), 2000); | |
}); | |
const third = new Promise((resolve, reject) => { | |
setTimeout(() => resolve("third"), 3000); |
NewerOlder