Skip to content

Commit 01bec29

Browse files
committed
feat: add golang solution to lcci problem: No.01.01.Is Unique
1 parent 190c9a3 commit 01bec29

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

lcci/01.01.Is Unique/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ class Solution {
9191
};
9292
```
9393

94+
### **Go**
95+
96+
```go
97+
func isUnique(astr string) bool {
98+
bitmap := 0
99+
for _, r := range astr {
100+
pos := r - 'a'
101+
if (bitmap & (1 << pos)) != 0 {
102+
return false
103+
}
104+
bitmap |= (1 << pos)
105+
}
106+
return true
107+
}
108+
```
109+
94110
### **...**
95111

96112
```

lcci/01.01.Is Unique/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ class Solution {
8888
};
8989
```
9090

91+
### **Go**
92+
93+
```go
94+
func isUnique(astr string) bool {
95+
bitmap := 0
96+
for _, r := range astr {
97+
pos := r - 'a'
98+
if (bitmap & (1 << pos)) != 0 {
99+
return false
100+
}
101+
bitmap |= (1 << pos)
102+
}
103+
return true
104+
}
105+
```
106+
91107
### **...**
92108

93109
```

lcci/01.01.Is Unique/Solution.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
func isUnique(astr string) bool {
2+
bitmap := 0
3+
for _, r := range astr {
4+
pos := r - 'a'
5+
if (bitmap & (1 << pos)) != 0 {
6+
return false
7+
}
8+
bitmap |= (1 << pos)
9+
}
10+
return true
11+
}

0 commit comments

Comments
 (0)