We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 79b2292 commit dbe74a5Copy full SHA for dbe74a5
scripts/algorithms/R/Reordered Power of 2/Reordered Power of 2.js
@@ -1,21 +1,16 @@
1
+// Runtime: 48 ms (Top 84.09%) | Memory: 43.20 MB (Top 63.64%)
2
+
3
var reorderedPowerOf2 = function(n) {
- const orig = convert(n);
4
+ let str = n.toString();
5
+ let initialString = str.split('').sort().join('');
6
- let num = 1;
7
- while (num <= 1e9) {
- const str = convert(num);
8
-
9
- if (str === orig) return true;
10
- num <<= 1;
+ for(let i=0; i<30; i++){
+ let tempString = (1<<i).toString();
+ let finalString = tempString.split('').sort().join('');
11
+ if(initialString===finalString){
12
+ return true
13
+ }
14
}
- return false;
15
- function convert(num) {
16
- const str = num.toString();
17
- const digits = str.split("");
18
- const sort = digits.sort();
19
- return sort.join("#");
20
- }
21
-};
+ return false
+}
0 commit comments