File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2375. Construct Smallest Number From DI String
3
+ * https://leetcode.com/problems/construct-smallest-number-from-di-string/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a 0-indexed string pattern of length n consisting of the characters
7
+ * 'I' meaning increasing and 'D' meaning decreasing.
8
+ *
9
+ * A 0-indexed string num of length n + 1 is created using the following conditions:
10
+ * - num consists of the digits '1' to '9', where each digit is used at most once.
11
+ * - If pattern[i] == 'I', then num[i] < num[i + 1].
12
+ * - If pattern[i] == 'D', then num[i] > num[i + 1].
13
+ *
14
+ * Return the lexicographically smallest possible string num that meets the conditions.
15
+ */
16
+
17
+ /**
18
+ * @param {string } pattern
19
+ * @return {string }
20
+ */
21
+ var smallestNumber = function ( pattern ) {
22
+ let result = '' ;
23
+
24
+ for ( let i = 0 , stack = [ ] ; i <= pattern . length ; i ++ ) {
25
+ stack . push ( i + 1 ) ;
26
+ if ( i === pattern . length || pattern [ i ] === 'I' ) {
27
+ while ( stack . length > 0 ) {
28
+ result += stack . pop ( ) ;
29
+ }
30
+ }
31
+ }
32
+
33
+ return result ;
34
+ } ;
Original file line number Diff line number Diff line change 553
553
2349|[ Design a Number Container System] ( ./2349-design-a-number-container-system.js ) |Medium|
554
554
2352|[ Equal Row and Column Pairs] ( ./2352-equal-row-and-column-pairs.js ) |Medium|
555
555
2364|[ Count Number of Bad Pairs] ( ./2364-count-number-of-bad-pairs.js ) |Medium|
556
+ 2375|[ Construct Smallest Number From DI String] ( ./2375-construct-smallest-number-from-di-string.js ) |Medium|
556
557
2390|[ Removing Stars From a String] ( ./2390-removing-stars-from-a-string.js ) |Medium|
557
558
2396|[ Strictly Palindromic Number] ( ./2396-strictly-palindromic-number.js ) |Medium|
558
559
2413|[ Smallest Even Multiple] ( ./2413-smallest-even-multiple.js ) |Easy|
You can’t perform that action at this time.
0 commit comments