File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,708 LeetCode solutions in JavaScript
1
+ # 1,709 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1570
1570
2044|[ Count Number of Maximum Bitwise-OR Subsets] ( ./solutions/2044-count-number-of-maximum-bitwise-or-subsets.js ) |Medium|
1571
1571
2045|[ Second Minimum Time to Reach Destination] ( ./solutions/2045-second-minimum-time-to-reach-destination.js ) |Hard|
1572
1572
2047|[ Number of Valid Words in a Sentence] ( ./solutions/2047-number-of-valid-words-in-a-sentence.js ) |Easy|
1573
+ 2048|[ Next Greater Numerically Balanced Number] ( ./solutions/2048-next-greater-numerically-balanced-number.js ) |Medium|
1573
1574
2053|[ Kth Distinct String in an Array] ( ./solutions/2053-kth-distinct-string-in-an-array.js ) |Medium|
1574
1575
2071|[ Maximum Number of Tasks You Can Assign] ( ./solutions/2071-maximum-number-of-tasks-you-can-assign.js ) |Hard|
1575
1576
2085|[ Count Common Words With One Occurrence] ( ./solutions/2085-count-common-words-with-one-occurrence.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2048. Next Greater Numerically Balanced Number
3
+ * https://leetcode.com/problems/next-greater-numerically-balanced-number/
4
+ * Difficulty: Medium
5
+ *
6
+ * An integer x is numerically balanced if for every digit d in the number x, there are exactly
7
+ * d occurrences of that digit in x.
8
+ *
9
+ * Given an integer n, return the smallest numerically balanced number strictly greater than n.
10
+ */
11
+
12
+ /**
13
+ * @param {number } n
14
+ * @return {number }
15
+ */
16
+ var nextBeautifulNumber = function ( n ) {
17
+ let candidate = n + 1 ;
18
+ while ( candidate <= 10000000 ) {
19
+ if ( isBalanced ( candidate ) ) return candidate ;
20
+ candidate ++ ;
21
+ }
22
+
23
+ return - 1 ;
24
+
25
+ function isBalanced ( num ) {
26
+ const freq = new Array ( 10 ) . fill ( 0 ) ;
27
+ const str = num . toString ( ) ;
28
+
29
+ for ( const digit of str ) {
30
+ freq [ digit ] ++ ;
31
+ }
32
+
33
+ for ( const digit of str ) {
34
+ if ( freq [ digit ] !== parseInt ( digit ) ) return false ;
35
+ }
36
+
37
+ return true ;
38
+ }
39
+ } ;
You can’t perform that action at this time.
0 commit comments