Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ class Solution {
}
```

### **JavaScript**

```js
/**
* @param {string} s
* @return {boolean}
*/
var checkZeroOnes = function(s) {
let max0 = 0, max1 = 0;
let t0 = 0, t1 = 0;
for (let char of s) {
if (char == '0') {
t0++;
t1 = 0;
} else {
t1++;
t0 = 0;
}
max0 = Math.max(max0, t0);
max1 = Math.max(max1, t1);
}
return max1 > max0;
};
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ class Solution {
}
```

### **JavaScript**

```js
/**
* @param {string} s
* @return {boolean}
*/
var checkZeroOnes = function(s) {
let max0 = 0, max1 = 0;
let t0 = 0, t1 = 0;
for (let char of s) {
if (char == '0') {
t0++;
t1 = 0;
} else {
t1++;
t0 = 0;
}
max0 = Math.max(max0, t0);
max1 = Math.max(max1, t1);
}
return max1 > max0;
};
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @param {string} s
* @return {boolean}
*/
var checkZeroOnes = function(s) {
let max0 = 0, max1 = 0;
let t0 = 0, t1 = 0;
for (let char of s) {
if (char == '0') {
t0++;
t1 = 0;
} else {
t1++;
t0 = 0;
}
max0 = Math.max(max0, t0);
max1 = Math.max(max1, t1);
}
return max1 > max0;
};
36 changes: 36 additions & 0 deletions solution/1800-1899/1870.Minimum Speed to Arrive on Time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,42 @@ class Solution {
}
```

### **JavaScript**

```js
/**
* @param {number[]} dist
* @param {number} hour
* @return {number}
*/
var minSpeedOnTime = function(dist, hour) {
if (dist.length > Math.ceil(hour)) return -1;
let left = 1, right = 10 ** 7;
while (left < right) {
let mid = (left + right) >> 1;
if (arriveOnTime(dist, mid, hour)) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
};

function arriveOnTime (dist, speed, hour) {
let res = 0.0;
let n = dist.length;
for (let i = 0; i < n; i++) {
let cost = parseFloat(dist[i]) / speed;
if (i != n - 1) {
cost = Math.ceil(cost);
}
res += cost;
}
return res <= hour;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ class Solution {
}
```

### **JavaScript**

```js
/**
* @param {number[]} dist
* @param {number} hour
* @return {number}
*/
var minSpeedOnTime = function(dist, hour) {
if (dist.length > Math.ceil(hour)) return -1;
let left = 1, right = 10 ** 7;
while (left < right) {
let mid = (left + right) >> 1;
if (arriveOnTime(dist, mid, hour)) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
};

function arriveOnTime (dist, speed, hour) {
let res = 0.0;
let n = dist.length;
for (let i = 0; i < n; i++) {
let cost = parseFloat(dist[i]) / speed;
if (i != n - 1) {
cost = Math.ceil(cost);
}
res += cost;
}
return res <= hour;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @param {number[]} dist
* @param {number} hour
* @return {number}
*/
var minSpeedOnTime = function(dist, hour) {
if (dist.length > Math.ceil(hour)) return -1;
let left = 1, right = 10 ** 7;
while (left < right) {
let mid = (left + right) >> 1;
if (arriveOnTime(dist, mid, hour)) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
};

function arriveOnTime (dist, speed, hour) {
let res = 0.0;
let n = dist.length;
for (let i = 0; i < n; i++) {
let cost = parseFloat(dist[i]) / speed;
if (i != n - 1) {
cost = Math.ceil(cost);
}
res += cost;
}
return res <= hour;
}