Skip to content

Commit 0c08a1e

Browse files
author
Isaac Ramirez
committed
Add exercise 1.1 book solution.
1 parent 49cbbf8 commit 0c08a1e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Using a hash-table.
3+
* Running time: O(N)
4+
* @param {string} str
5+
* @returns {boolean}
6+
*/
7+
function isUniqueChars(str) {
8+
const charSet = {};
9+
10+
for (let i = 0; i < str.length; i++) {
11+
const code = str.charCodeAt(i);
12+
13+
if (charSet[code]) return false;
14+
15+
charSet[code] = true;
16+
}
17+
18+
return true;
19+
}
20+
21+
module.exports = isUniqueChars;

src/chapters/01/exercises/is-unique/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* Book solutions */
2+
const isUniqueSolution = require("./book-solution/is-unique.solution");
3+
/* My solutions */
14
const isUniqueV1 = require("./my-solution/is-unique.v1");
25

36
/* Export the solution to be tested */

0 commit comments

Comments
 (0)