Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81c0c8e

Browse files
committed
Add solution #2042
1 parent 7ad2c64 commit 81c0c8e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,703 LeetCode solutions in JavaScript
1+
# 1,704 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1565,6 +1565,7 @@
15651565
2038|[Remove Colored Pieces if Both Neighbors are the Same Color](./solutions/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.js)|Medium|
15661566
2039|[The Time When the Network Becomes Idle](./solutions/2039-the-time-when-the-network-becomes-idle.js)|Medium|
15671567
2040|[Kth Smallest Product of Two Sorted Arrays](./solutions/2040-kth-smallest-product-of-two-sorted-arrays.js)|Hard|
1568+
2042|[Check if Numbers Are Ascending in a Sentence](./solutions/2042-check-if-numbers-are-ascending-in-a-sentence.js)|Easy|
15681569
2047|[Number of Valid Words in a Sentence](./solutions/2047-number-of-valid-words-in-a-sentence.js)|Easy|
15691570
2053|[Kth Distinct String in an Array](./solutions/2053-kth-distinct-string-in-an-array.js)|Medium|
15701571
2071|[Maximum Number of Tasks You Can Assign](./solutions/2071-maximum-number-of-tasks-you-can-assign.js)|Hard|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 2042. Check if Numbers Are Ascending in a Sentence
3+
* https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/
4+
* Difficulty: Easy
5+
*
6+
* A sentence is a list of tokens separated by a single space with no leading or trailing spaces.
7+
* Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a
8+
* word consisting of lowercase English letters.
9+
* - For example, "a puppy has 2 eyes 4 legs" is a sentence with seven tokens: "2" and "4" are
10+
* numbers and the other tokens such as "puppy" are words.
11+
*
12+
* Given a string s representing a sentence, you need to check if all the numbers in s are strictly
13+
* increasing from left to right (i.e., other than the last number, each number is strictly smaller
14+
* than the number on its right in s).
15+
*
16+
* Return true if so, or false otherwise.
17+
*/
18+
19+
/**
20+
* @param {string} s
21+
* @return {boolean}
22+
*/
23+
var areNumbersAscending = function(s) {
24+
const numbers = s.split(' ').filter(token => !isNaN(token)).map(Number);
25+
for (let i = 1; i < numbers.length; i++) {
26+
if (numbers[i] <= numbers[i - 1]) return false;
27+
}
28+
return true;
29+
};

0 commit comments

Comments
 (0)