Skip to content

Commit a430fc4

Browse files
committed
update solution contains duplicate
1 parent 5465bdf commit a430fc4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/data_structure/hashmap/roman-to-integer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function romanToInt(s: string): number {
3333
return sum
3434
};
3535

36-
36+
// Space O(1), Time O(n)
3737
romanToInt("III");
3838
romanToInt("LVIII");
3939
romanToInt("MCMXCIV");

src/leetcode/array/contains-duplicate.test.ts

Whitespace-only changes.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function containsDuplicate(nums: number[]): boolean {
2+
3+
const dict: Record<string, any> = {} // O(n) space
4+
for (let i = 0; i < nums.length; i++) {
5+
if (dict[nums[i]]) {
6+
return true
7+
} else {
8+
dict[nums[i]] = 1
9+
}
10+
}
11+
12+
return false
13+
14+
};
15+
16+
console.log("contains: ", containsDuplicate([1, 2, 3]));

0 commit comments

Comments
 (0)