mirror of
https://github.com/prdlk/leetcode.git
synced 2026-08-02 17:31:40 +00:00
docs: remove redundant documentation files and table of contents from README
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
# LeetCode
|
||||
|
||||
<!--toc:start-->
|
||||
- [LeetCode](#leetcode)
|
||||
- [Introduction](#introduction)
|
||||
- [Frequency Map + Sort-With-Tiebreaker](#frequency-map-sort-with-tiebreaker)
|
||||
- [Event Emitter + Throttle](#event-emitter-throttle)
|
||||
<!--toc:end-->
|
||||
|
||||
## Introduction
|
||||
|
||||
Day 1: Frequency map + sort-with-tiebreak until automatic (LC 1365, 1636, 451)
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# Leetcode 1365
|
||||
|
||||
<!--toc:start-->
|
||||
- [Leetcode 1365](#leetcode-1365)
|
||||
- [Creating a Frequancy Map](#creating-a-frequancy-map)
|
||||
- [Hammer Tool](#hammer-tool)
|
||||
<!--toc:end-->
|
||||
|
||||
```js
|
||||
function reduceArray(nums) {
|
||||
const sorted = [...nums].sort((a, b) => a - b)
|
||||
return nums.map((x) => {
|
||||
nums.indexOf(sorted[x])
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Creating a Frequancy Map
|
||||
|
||||
```js
|
||||
function reduceArray(nums) {
|
||||
const freqMap = new Map()
|
||||
nums.forEach((x) => {
|
||||
if (freqMap.has(x)) {
|
||||
freqMap.set(x, freqMap.get(x) + 1)
|
||||
} else {
|
||||
freqMap.set(x, 1)
|
||||
}
|
||||
})
|
||||
return Array.from(freqMap.entries()).map(([k, v]) => v)
|
||||
}
|
||||
```
|
||||
|
||||
### Hammer Tool
|
||||
|
||||
```js
|
||||
function hammer(arrOrStr) {
|
||||
const freq = {};
|
||||
for (let item of arrOrStr) {
|
||||
freq[item] = (freq[item] || 0) + 1;
|
||||
}
|
||||
|
||||
// Then either:
|
||||
// A. Return freq map
|
||||
// B. Sort using freq
|
||||
return arrOrStr.slice().sort((a, b) => {
|
||||
if (freq[b] !== freq[a]) return freq[b] - freq[a]; // desc freq
|
||||
return a < b ? -1 : 1; // tiebreaker
|
||||
});
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user