-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problems: No.1604~1608 (#2478)
- Loading branch information
Showing
6 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
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
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
29 changes: 29 additions & 0 deletions
29
...-1699/1604.Alert Using Same Key-Card Three or More Times in a One Hour Period/Solution.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function alertNames(keyName: string[], keyTime: string[]): string[] { | ||
const d: { [name: string]: number[] } = {}; | ||
for (let i = 0; i < keyName.length; ++i) { | ||
const name = keyName[i]; | ||
const t = keyTime[i]; | ||
const minutes = +t.slice(0, 2) * 60 + +t.slice(3); | ||
if (d[name] === undefined) { | ||
d[name] = []; | ||
} | ||
d[name].push(minutes); | ||
} | ||
const ans: string[] = []; | ||
for (const name in d) { | ||
if (d.hasOwnProperty(name)) { | ||
const ts = d[name]; | ||
if (ts.length > 2) { | ||
ts.sort((a, b) => a - b); | ||
for (let i = 0; i < ts.length - 2; ++i) { | ||
if (ts[i + 2] - ts[i] <= 60) { | ||
ans.push(name); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
ans.sort(); | ||
return ans; | ||
} |
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
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
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