Skip to content

Commit

Permalink
Create index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Sep 11, 2022
1 parent 64fa9d3 commit 89f816b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions check-distances-between-same-letters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default function checkDistances(s: string, distance: number[]): boolean {
const mp=new Map<number,number>()

for(const [i,c]of Array.prototype.entries.call(s)){



const key=c.charCodeAt(0)-"a".charCodeAt(0)
const last=mp.get(key)

if(mp.has(key)&&typeof last !=="undefined"&&i-last-1!==distance[key]){

return false

}else{
mp.set(key,i)
}
}
return true
}

0 comments on commit 89f816b

Please sign in to comment.