Skip to content

Commit 2a7bc9c

Browse files
committed
feat: update solution to lcci problem: No.01.01. Is Unique
1 parent b7ca313 commit 2a7bc9c

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

lcci/01.01.Is Unique/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ class Solution {
7171
}
7272
```
7373

74+
### **JavaScript**
75+
76+
```js
77+
/**
78+
* @param {string} astr
79+
* @return {boolean}
80+
*/
81+
var isUnique = function(astr) {
82+
let bitmap = 0;
83+
for (let i = 0; i < astr.length; ++i) {
84+
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
85+
if ((bitmap & (1 << pos)) != 0) {
86+
return false;
87+
}
88+
bitmap |= (1 << pos);
89+
}
90+
return true;
91+
};
92+
```
93+
7494
### **...**
7595

7696
```

lcci/01.01.Is Unique/README_EN.md

+20
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ class Solution {
6868
}
6969
```
7070

71+
### **JavaScript**
72+
73+
``` js
74+
/**
75+
* @param {string} astr
76+
* @return {boolean}
77+
*/
78+
var isUnique = function(astr) {
79+
let bitmap = 0;
80+
for (let i = 0; i < astr.length; ++i) {
81+
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
82+
if ((bitmap & (1 << pos)) != 0) {
83+
return false;
84+
}
85+
bitmap |= (1 << pos);
86+
}
87+
return true;
88+
};
89+
```
90+
7191
### **...**
7292

7393
```

lcci/01.01.Is Unique/Solution.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string} astr
3+
* @return {boolean}
4+
*/
5+
var isUnique = function(astr) {
6+
let bitmap = 0;
7+
for (let i = 0; i < astr.length; ++i) {
8+
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
9+
if ((bitmap & (1 << pos)) != 0) {
10+
return false;
11+
}
12+
bitmap |= (1 << pos);
13+
}
14+
return true;
15+
};

0 commit comments

Comments
 (0)