Skip to content

Commit 2ec03fe

Browse files
add 1093 js
1 parent 3421b8d commit 2ec03fe

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ LeetCode
430430
|1089|[Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/) | c | [c++](./src/1089-Duplicate-Zeros/1089.cpp) |[python](./src/1089-Duplicate-Zeros/1089.py)|||Easy|
431431
|1090|[Largest Values From Labels](https://leetcode.com/problems/largest-values-from-labels/) | c | [c++](./src/1090-Largest-Values-From-Labels/1090.cpp) |[python](./src/1090-Largest-Values-From-Labels/1090.py)|||Medium|
432432
|1091|[Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/) | c | [c++](./src/1091-Shortest-Path-in-Binary-Matrix/1091.cpp) |[python](./src/1091-Shortest-Path-in-Binary-Matrix/1091.py)|[go](./src/1091-Shortest-Path-in-Binary-Matrix/1091.go)|[js](./src/1091-Shortest-Path-in-Binary-Matrix/1091.js)|Medium|
433-
|1093|[Statistics from a Large Sample](https://leetcode.com/problems/statistics-from-a-large-sample/) | c | [c++](./src/1093-Statistics-from-a-Large-Sample/1093.cpp) |[python](./src/1093-Statistics-from-a-Large-Sample/1093.py)|[go](./src/1093-Statistics-from-a-Large-Sample/1093.go)||Medium|
433+
|1093|[Statistics from a Large Sample](https://leetcode.com/problems/statistics-from-a-large-sample/) | c | [c++](./src/1093-Statistics-from-a-Large-Sample/1093.cpp) |[python](./src/1093-Statistics-from-a-Large-Sample/1093.py)|[go](./src/1093-Statistics-from-a-Large-Sample/1093.go)|[js](./src/1093-Statistics-from-a-Large-Sample/1093.js)|Medium|
434434
|1094|[Car Pooling](https://leetcode.com/problems/car-pooling/) | c | [c++](./src/1094-Car-Pooling/1094.cpp) |[python](./src/1094-Car-Pooling/1094.py)|[go](./src/1094-Car-Pooling/1094.go)||Medium|
435435
|1095|[Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array/) | c | [c++](./src/1095-Find-in-Mountain-Array/1095.cpp) |[python](./src/1095-Find-in-Mountain-Array/1095.py)|[go](./src/1095-Find-in-Mountain-Array/1095.go)||Hard|
436436
|1096|[Brace Expansion II](https://leetcode.com/problems/brace-expansion-ii/) | c | [c++](./src/1096-Brace-Expansion-II/1096.cpp) |[python](./src/1096-Brace-Expansion-II/1096.py)|[go](./src/1096-Brace-Expansion-II/1096.go)||Hard|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var sampleStats = function(count) {
2+
var res = [255, 0, 0, 0, 0];
3+
var sum_all = count.reduce(function(pre, cur) {
4+
return pre + cur;
5+
}, 0);
6+
7+
var l = sum_all / 2, r = l + (sum_all & 1 ? 0 : 1), m_cnt = 0;
8+
for (var i = 0, cnt = 0; i < count.length; cnt += count[i++]) {
9+
res[0] = count[i] ? Math.min(res[0], i) : res[0];
10+
res[1] = count[i] ? i : res[1];
11+
res[2] += i * count[i] / sum_all;
12+
if (cnt < l && cnt + count[i] >= l) res[3] += i / 2;
13+
if (cnt < r && cnt + count[i] >= r) res[3] += i / 2;
14+
if (m_cnt < count[i]) {
15+
m_cnt = count[i];
16+
res[4] = i;
17+
}
18+
}
19+
return res;
20+
};

0 commit comments

Comments
 (0)