question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reordered-power-of-2 | 🔥 Python || Easily Understood ✅ || Faster than 96% || Fast | python-easily-understood-faster-than-96-fpukz | Appreciate if you could upvote this solution\n\nSince the maximun of n is 10^9 and the len(str(10**9)) is 10 which is complicated to get all the combinations of | wingskh | NORMAL | 2022-08-26T10:16:37.006070+00:00 | 2022-08-26T10:16:37.006106+00:00 | 2,227 | false | **Appreciate if you could upvote this solution**\n\nSince the maximun of `n` is 10^9 and the `len(str(10**9))` is 10 which is complicated to get all the combinations of the digits.\n\nThus, we resolved this questions to:\n**If the digit combination of n match the digit combinations of all the power of 2**\n\nThen, it i... | 32 | 1 | ['Python'] | 3 |
reordered-power-of-2 | ✔️Python🔥One-liner✅Bit shift | Detailed explain | Beginner-friendly | Easy understand | pythonone-linerbit-shift-detailed-explai-c1lq | Main idea:\n1. We loop through 1 to 2^29 using Bit shift.\n2. And using Counter() to check if every digit in n is in power of two.\n\nOne-liner code:\npython\nc | luluboy168 | NORMAL | 2022-08-26T08:03:45.827361+00:00 | 2022-08-26T08:03:45.827402+00:00 | 1,731 | false | **Main idea:**\n1. We loop through 1 to 2^29 using Bit shift.\n2. And using Counter() to check if every digit in n is in power of two.\n\n**One-liner code:**\n```python\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n return Counter(str(n)) in [Counter(str(1 << i)) for i in range(30)]\n```\n\... | 27 | 0 | ['Python'] | 4 |
reordered-power-of-2 | Python Solution | Detailed Explanation with Example | python-solution-detailed-explanation-wit-kl9i | Intuition\n Describe your first thoughts on how to solve this problem. \nWe know that in this question, the input n is less and equal to 10\u2079 so the powers | graceyliy29 | NORMAL | 2023-01-30T23:01:12.099324+00:00 | 2023-01-30T23:01:12.099373+00:00 | 660 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe know that in this question, the input n is less and equal to 10\u2079 so the powers of 2 can be 1, 2, 4, and 8 all the way up to 2 to the power of 29 since 2\xB2\u2079 is less than 10\u2079 and 10\u2079 is less than 2\xB3\u2070.\n\n![i... | 23 | 0 | ['Python'] | 1 |
reordered-power-of-2 | Reordered Power of 2 | JS, Python, Java, C++ | Easy, Short Solution w/ Explanation | reordered-power-of-2-js-python-java-c-ea-1k20 | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-03-21T08:06:15.866301+00:00 | 2021-03-21T09:04:40.633202+00:00 | 823 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them bot... | 21 | 7 | [] | 2 |
reordered-power-of-2 | ✅ Simple & Easy w/ Explanation | beats 100% | Shortest Clean Code | simple-easy-w-explanation-beats-100-shor-kc1u | Solution - I (Counting Digits Frequency)\n\nA simple solution is to check if frequency of digits in N and all powers of 2 less than 10^9 are equal. In our case, | archit91 | NORMAL | 2021-03-21T09:15:32.993156+00:00 | 2021-03-21T14:49:03.454819+00:00 | 890 | false | ***Solution - I (Counting Digits Frequency)***\n\nA simple solution is to check if frequency of digits in N and all powers of 2 less than `10^9` are equal. In our case, we need to check for all powers of 2 from `2^0` to `2^29` and if any of them matches with digits in `N`, return true.\n\n```\n// counts frequency of ea... | 19 | 2 | ['C'] | 0 |
reordered-power-of-2 | [Python] Find anagram, explained | python-find-anagram-explained-by-dbabich-ucp0 | This is in fact question about anagrams: given string we need to find if we have another string from list of powers of too, which is anagram of original string. | dbabichev | NORMAL | 2021-03-21T08:22:36.964596+00:00 | 2021-03-21T08:22:36.964626+00:00 | 918 | false | This is in fact question about anagrams: given string we need to find if we have another string from list of powers of too, which is anagram of original string. Let us iterate through all powers of two and check if count of this number is equal to count of given number `N`. \n\n**Complexity**: time complexity will be `... | 18 | 2 | [] | 2 |
reordered-power-of-2 | ✅ From brute force to optimziation | Fully Explained | from-brute-force-to-optimziation-fully-e-8f3q | In this post, I shared my full thought process behind the question, and how I arrived at the optimal solution.\n\nIn contrast to just posting the answer, I try | nadaralp | NORMAL | 2022-08-26T06:07:37.529560+00:00 | 2022-08-26T06:12:28.543107+00:00 | 1,040 | false | In this post, I shared my full thought process behind the question, and how I arrived at the optimal solution.\n\nIn contrast to just posting the answer, I try to teach and show how to tackle problems and arrive progressively at the optimal solution, instead of memorizing them :)\n\n<hr />\n\nThe problem states that we... | 14 | 1 | ['Python'] | 2 |
reordered-power-of-2 | Clean and Easy to Understand digits Anagram | clean-and-easy-to-understand-digits-anag-huzz | \nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int i = 0, num = 1; i < 32; i++, num <<= 1)\n if(Arrays.equals(digitFr | i18n | NORMAL | 2021-03-21T11:52:53.376726+00:00 | 2021-03-21T11:52:53.376767+00:00 | 816 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int i = 0, num = 1; i < 32; i++, num <<= 1)\n if(Arrays.equals(digitFreq(N), digitFreq(num)))\n return true;\n \n return false;\n }\n \n private int[] digitFreq(int N) {\n int[] f = ... | 14 | 4 | [] | 0 |
reordered-power-of-2 | C++ 0ms beats 100% | c-0ms-beats-100-by-soundsoflife-f0eo | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n set<string> si = {"1", "2", "4", "8", "16", "23", "46", "128", "256", "125", "0124", " | soundsoflife | NORMAL | 2018-08-13T11:23:42.450612+00:00 | 2018-09-02T01:17:02.330712+00:00 | 1,076 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n set<string> si = {"1", "2", "4", "8", "16", "23", "46", "128", "256", "125", "0124", "0248", "0469", "1289",\n "13468", "23678", "35566", "011237", "122446", "224588", "0145678", "0122579", "0134449",\n ... | 14 | 5 | [] | 1 |
reordered-power-of-2 | JAVA Naive Backtracking 15 lines | java-naive-backtracking-15-lines-by-cara-mm9w | \nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n char[] ca=(N+"").toCharArray();\n return helper(ca, 0, new boolean[ca.length]) | caraxin | NORMAL | 2018-07-15T03:01:41.591307+00:00 | 2018-09-11T09:38:32.034219+00:00 | 1,753 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n char[] ca=(N+"").toCharArray();\n return helper(ca, 0, new boolean[ca.length]);\n }\n public boolean helper(char[] ca, int cur, boolean[] used){\n if (cur!=0 && (cur+"").length()==ca.length){\n if (Integer.bitCo... | 13 | 2 | [] | 1 |
reordered-power-of-2 | JAVA || Easy Solution Using HashSet | java-easy-solution-using-hashset-by-shiv-x7f0 | \tPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n Set<Long> two = new HashSet<>();\n for (int i = | shivrastogi | NORMAL | 2022-08-26T02:59:52.577941+00:00 | 2022-08-26T02:59:52.577971+00:00 | 1,772 | false | \tPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n Set<Long> two = new HashSet<>();\n for (int i = 1; i <= (int)1e9; i <<= 1){\n two.add(transform(i));\n }\n\n return two.contains(transform(n));\n }\n\n private long transform... | 12 | 1 | ['Java'] | 7 |
reordered-power-of-2 | Simple Python check upto 2 power 30 | simple-python-check-upto-2-power-30-by-c-szc0 | \n def reorderedPowerOf2(self, N):\n c1 = Counter(str(N))\n for i in range(30):\n n = int(math.pow(2, i))\n if Counter(st | Cubicon | NORMAL | 2018-07-15T03:01:55.089953+00:00 | 2018-10-09T05:04:41.496251+00:00 | 745 | false | ```\n def reorderedPowerOf2(self, N):\n c1 = Counter(str(N))\n for i in range(30):\n n = int(math.pow(2, i))\n if Counter(str(n)) == c1: return True\n return False\n``` | 11 | 1 | [] | 0 |
reordered-power-of-2 | C++ Easy Solution of Vector | c-easy-solution-of-vector-by-conquistado-qint | \nclass Solution {\npublic:\n vector<int> Helper(long n){\n vector<int>num(10);\n \n while(n){\n num[n%10]++;\n n= | Conquistador17 | NORMAL | 2022-08-26T02:46:36.943937+00:00 | 2022-08-26T02:46:36.943977+00:00 | 1,782 | false | ```\nclass Solution {\npublic:\n vector<int> Helper(long n){\n vector<int>num(10);\n \n while(n){\n num[n%10]++;\n n=n/10;\n }\n return num;\n }\n bool reorderedPowerOf2(int n) {\n vector<int>v=Helper(n);\n for(int i=0;i<31;i++){\n ... | 10 | 0 | ['C', 'C++'] | 4 |
reordered-power-of-2 | Python 27 ms (faster than 100%), new idea to improve other's solutions | python-27-ms-faster-than-100-new-idea-to-bs70 | Like others solutions, i use the same idea of counting the digits and then compare with digits of candidates: 1, 2, 4, 8, 16, 32, 64 ... 2^30.\nBut i noticed th | Splish-Splash | NORMAL | 2022-08-26T01:52:29.755772+00:00 | 2022-08-26T21:10:07.605063+00:00 | 925 | false | Like others solutions, i use the same idea of counting the digits and then compare with digits of candidates: ```1, 2, 4, 8, 16, 32, 64 ... 2^30```.\nBut i noticed that if our input is for example ```251``` we need to compare it only with power of 2 numbers that have exact 3 digits: ```128, 256, 512```, but how can we ... | 9 | 0 | ['Math', 'Sorting', 'Python'] | 6 |
reordered-power-of-2 | Python/Go O(log n) by digit-occurrence mapping [w/ Comment] | pythongo-olog-n-by-digit-occurrence-mapp-nz9y | For example:\n\nGiven power of 2 = 2 ^ 6 = 64\n\n64 => {6: 1, 4: 1}\n6 shows up one time\n4 shows up one time\n\n---\n\nN=46 or N=64 return true because their d | brianchiang_tw | NORMAL | 2021-03-21T08:27:13.881918+00:00 | 2021-03-23T12:59:29.456579+00:00 | 628 | false | For example:\n\nGiven power of 2 = 2 ^ 6 = 64\n\n64 => {6: 1, 4: 1}\n6 shows up one time\n4 shows up one time\n\n---\n\nN=46 or N=64 return **true** because their **digit - occurrence mapping** are the same with 64\n\n46 => {4: 1, 6: 1}\n4 shows up one time\n6 shows up one time\n\n64 => {6: 1, 4: 1}\n6 shows up one tim... | 9 | 0 | ['Recursion', 'Python', 'Go', 'Python3'] | 1 |
reordered-power-of-2 | Possibly fastest C++ solution using Multiset, 0ms runtime. | possibly-fastest-c-solution-using-multis-5fxa | So, the idea is very simple:\n1. Convert N into a multiset of its digits, for an example, if N = 426412 then the multiset will contain {1, 2, 2, 4, 4, 6}.\n2. N | mbanik | NORMAL | 2018-07-16T05:24:20.154604+00:00 | 2018-07-16T05:24:20.154604+00:00 | 1,085 | false | **So, the idea is very simple:**\n1. Convert `N` into a multiset of its digits, for an example, if `N = 426412` then the multiset will contain `{1, 2, 2, 4, 4, 6}`.\n2. Now, we will generate some 2\'s power and will convert them into another multiset as well, **if both multiset are same**, function will return **true**... | 9 | 1 | [] | 3 |
reordered-power-of-2 | [LeetCode The Hard Way] Easy Sorting with Explanation | leetcode-the-hard-way-easy-sorting-with-ihmq6 | Please check out LeetCode The Hard Way for more solution explanations and tutorials. If you like it, please give a star and watch my Github Repository.\n\n---\n | __wkw__ | NORMAL | 2022-08-26T03:12:47.027856+00:00 | 2022-08-26T03:12:47.027898+00:00 | 559 | false | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. If you like it, please give a star and watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way).\n\n---\n\n```cpp\nclass Solution {\npublic:\n string sort... | 6 | 0 | ['Bit Manipulation', 'C', 'Sorting', 'C++'] | 2 |
reordered-power-of-2 | 🗓️ Daily LeetCoding Challenge August, Day 26 | daily-leetcoding-challenge-august-day-26-cr6b | This problem is the Daily LeetCoding Challenge for August, Day 26. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2022-08-26T00:00:22.161205+00:00 | 2022-08-26T00:00:22.161290+00:00 | 2,923 | false | This problem is the Daily LeetCoding Challenge for August, Day 26.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please cr... | 6 | 0 | [] | 48 |
reordered-power-of-2 | [JavaScript] Easy to understand - 4 solutions | javascript-easy-to-understand-4-solution-0an5 | For this problem, there are 2 main strategies to solve it:\n- One is following the rules in the description and try every possible option.\n- Another one is to | poppinlp | NORMAL | 2021-03-22T08:54:45.809266+00:00 | 2021-03-22T08:54:45.809292+00:00 | 415 | false | For this problem, there are 2 main strategies to solve it:\n- One is following the rules in the description and try every possible option.\n- Another one is to try to find a way to serialize the number and check whether the serialization for `N` matches any serialization of power of 2.\n\n## SOLUTION 1\n\nFirst, we try... | 6 | 0 | ['JavaScript'] | 0 |
reordered-power-of-2 | [C++] Linear Time, Constant Space Solution Explained, 100% Time, 100% Space | c-linear-time-constant-space-solution-ex-87k4 | Great problem to tackle and, since it was pretty straightforward, I gave myself a few extra challenges:\n no conversion to string (that will not look cool to mo | ajna | NORMAL | 2021-03-21T10:23:05.397443+00:00 | 2021-03-21T13:30:29.634109+00:00 | 619 | false | Great problem to tackle and, since it was pretty straightforward, I gave myself a few extra challenges:\n* no conversion to string (that will not look cool to most interviewers anyway);\n* no sorting;\n* getting there with constant space.\n\nAnd it looks like I did it \uD83C\uDF8A !\n\nIn order to proceed, first of all... | 6 | 2 | ['C', 'C++'] | 1 |
reordered-power-of-2 | C++ | Efficient Solution | Easy | c-efficient-solution-easy-by-ansaine-f1km | \nbool reorderedPowerOf2(int n) {\n \n if(n==1)\n return true;\n \n string num = to_string(n);\n sort(num.begin(),num.end());\n \n | Ansaine | NORMAL | 2022-08-26T14:29:53.580480+00:00 | 2022-08-26T14:29:53.580514+00:00 | 330 | false | ```\nbool reorderedPowerOf2(int n) {\n \n if(n==1)\n return true;\n \n string num = to_string(n);\n sort(num.begin(),num.end());\n \n unordered_map<string,int> powers;\n \n //creating all 0 to 29 possible powers of 2;\n for(int i =0 ; i<=29; i++){\n string str = to_string... | 5 | 0 | ['C'] | 0 |
reordered-power-of-2 | C++ | Easy solution | c-easy-solution-by-ansaine-z28d | \nclass Solution {\npublic:\n \nbool isPowerOfTwo(int n) { \n if(n==0)\n return 0;\n \n if(ceil(log2(n)) == floor(log2(n)))\n | Ansaine | NORMAL | 2022-08-26T13:50:10.683491+00:00 | 2022-08-26T13:50:10.683530+00:00 | 215 | false | ```\nclass Solution {\npublic:\n \nbool isPowerOfTwo(int n) { \n if(n==0)\n return 0;\n \n if(ceil(log2(n)) == floor(log2(n)))\n return 1;\n else\n return 0; \n}\n \n \nbool reorderedPowerOf2(int n) {\n \n string num = to_string(n);\n sort(num... | 5 | 0 | ['C', 'Probability and Statistics'] | 0 |
reordered-power-of-2 | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-a2v6 | Using Hashmap\n\n Time Complexity :- O(Constant * logN)\n\n Space Complexity :- O(Constant)\n\n\nclass Solution {\npublic:\n \n // function for checking i | __KR_SHANU_IITG | NORMAL | 2022-08-26T04:19:40.624782+00:00 | 2022-08-26T04:19:40.624826+00:00 | 346 | false | * ***Using Hashmap***\n\n* ***Time Complexity :- O(Constant * logN)***\n\n* ***Space Complexity :- O(Constant)***\n\n```\nclass Solution {\npublic:\n \n // function for checking is two numbers have identiacal digits\n \n bool is_possible(int num1, int num2)\n {\n vector<int> mp(10, 0);\n \n... | 5 | 0 | ['C', 'Counting', 'C++'] | 1 |
reordered-power-of-2 | python3 | easy understanding | sort | python3-easy-understanding-sort-by-h-r-s-hww6 | \nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n i, arr = 0, []\n v = 2**i\n while v <= 10**9: arr.append(sorted(str(v | H-R-S | NORMAL | 2022-08-26T01:55:08.837660+00:00 | 2022-08-26T01:55:08.837696+00:00 | 1,001 | false | ```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n i, arr = 0, []\n v = 2**i\n while v <= 10**9: arr.append(sorted(str(v))); i+=1; v = 2**i\n return sorted(str(n)) in arr\n``` | 5 | 1 | ['Math', 'Sorting', 'Python3'] | 1 |
reordered-power-of-2 | Python My Soln | python-my-soln-by-lucasschnee-lm1z | class Solution:\n\n def reorderedPowerOf2(self, n: int) -> bool:\n n1 = sorted(str(n))\n \n for i in range(30):\n res = sorte | lucasschnee | NORMAL | 2022-08-26T01:30:16.032730+00:00 | 2022-08-26T01:30:16.032782+00:00 | 1,000 | false | class Solution:\n\n def reorderedPowerOf2(self, n: int) -> bool:\n n1 = sorted(str(n))\n \n for i in range(30):\n res = sorted(str(2 ** i))\n if res == n1:\n return True\n \n \n return False | 5 | 0 | ['Python', 'Python3'] | 6 |
reordered-power-of-2 | [Java] - count occurance of digits | java-count-occurance-of-digits-by-dark_w-hq87 | From the problem description it is clear that we need to check whether N is a permutation of a power of 2. The approach is the following:\n\nIn the first step, | dark_warlord | NORMAL | 2021-03-21T07:53:09.423054+00:00 | 2021-03-21T07:53:09.423096+00:00 | 99 | false | From the problem description it is clear that we need to check whether N is a permutation of a power of 2. The approach is the following:\n\nIn the first step, we count the occurance of each digit (0-9) in N\n\nIn the second step, we go through each power of 2 (say, x). For each x, we do the following:\n1. Count the oc... | 5 | 3 | [] | 0 |
reordered-power-of-2 | [python 3] | python-3-by-bakerston-mfk7 | \ndef reorderedPowerOf2(self, N: int) -> bool:\n c, l = collections.Counter(str(N)), len(str(N))\n n = 1\n while len(str(n)) <= l:\n | Bakerston | NORMAL | 2021-01-10T21:39:12.380397+00:00 | 2021-01-10T21:39:12.380442+00:00 | 102 | false | ```\ndef reorderedPowerOf2(self, N: int) -> bool:\n c, l = collections.Counter(str(N)), len(str(N))\n n = 1\n while len(str(n)) <= l:\n if collections.Counter(str(n)) == c:\n return True\n n *= 2\n return False\n``` | 5 | 0 | [] | 0 |
reordered-power-of-2 | One line python beats 70% | one-line-python-beats-70-by-mopriestt-tvnq | \nclass Solution:\n def reorderedPowerOf2(self, N):\n return sorted(str(N)) in [sorted(str(1<<i)) for i in range(33)]\n | mopriestt | NORMAL | 2018-09-21T15:54:17.908439+00:00 | 2018-10-01T02:31:42.726166+00:00 | 689 | false | ```\nclass Solution:\n def reorderedPowerOf2(self, N):\n return sorted(str(N)) in [sorted(str(1<<i)) for i in range(33)]\n``` | 5 | 0 | [] | 2 |
reordered-power-of-2 | ⚡⚡ Lightining Fast | 🧠🧠 High IQ | 🦸♂️🦸♂️ Marvel Approach | lightining-fast-high-iq-marvel-approach-du4q8 | Logic?\n\nWe have used a special operation here " << " , which is know as binary left operator. The left operands value is moved left by the number of bits sp | sHadowSparK | NORMAL | 2022-08-26T18:45:47.122132+00:00 | 2022-08-26T19:25:04.205026+00:00 | 163 | false | **Logic?**\n\nWe have used a special operation here " **<<** " , which is know as **binary left operator**. The left operands value is moved left by the number of bits specified by the right operand.\n\nSo ,\n*1 = 00000000 00000000 00000000 00000001 = 1*\n*1 << 1 = 00000000 00000000 00000000 00000010 = 2*\n*1 <<... | 4 | 0 | ['C'] | 0 |
reordered-power-of-2 | best JAVA solution | best-java-solution-by-ayushsharma57-1pvn | \nTC : Calculating the frequency Count for a no would be O(no of digits in N). Also,there could a case where it matches with 2^31 (last power of 2).So the compl | AyushSharma57 | NORMAL | 2022-08-26T16:13:02.193178+00:00 | 2022-08-26T16:15:38.882982+00:00 | 46 | false | \n**TC : Calculating the frequency Count for a no would be O(no of digits in N). Also,there could a case where it matches with 2^31 (last power of 2).So the complexity would be O(32*length(2^32) + O(no of digits in N)**\n```\nclass Solution { \n \n public boolean reorderedPowerOf2(int n) \n {\n\t\tint [] nFreq... | 4 | 0 | ['Array'] | 0 |
reordered-power-of-2 | one easy way to solve | one-easy-way-to-solve-by-jahidaladin-omfv | \nvar reorderedPowerOf2 = function(n) {\n let str = n.toString();\n let initialString = str.split(\'\').sort().join(\'\');\n \n \n for(let i=0; i | jahidaladin | NORMAL | 2022-08-26T13:20:05.558610+00:00 | 2022-08-26T13:20:05.558651+00:00 | 291 | false | ```\nvar reorderedPowerOf2 = function(n) {\n let str = n.toString();\n let initialString = str.split(\'\').sort().join(\'\');\n \n \n for(let i=0; i<30; i++){\n let tempString = (1<<i).toString();\n let finalString = tempString.split(\'\').sort().join(\'\');\n if(initialString===final... | 4 | 0 | ['JavaScript'] | 0 |
reordered-power-of-2 | 100.00% of c++|| 2 approach ||Using Map and sorting || optimise space | 10000-of-c-2-approach-using-map-and-sort-aok8 | 1st approach using only sorting function\n\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) { \n vector<string>v;\n \n for(int | Akash-Jha | NORMAL | 2022-08-26T09:06:28.056690+00:00 | 2022-08-26T09:07:55.911238+00:00 | 351 | false | **1st approach using only sorting function**\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) { \n vector<string>v;\n \n for(int i=0;i<=30;i++){\n int p = pow(2 , i);\n v.push_back(to_string(p));\n }\n \n for(int i=0;i<=30;i++){\n ... | 4 | 0 | ['C', 'Sorting'] | 1 |
reordered-power-of-2 | [C++] 0 ms, faster than 100.00% | c-0-ms-faster-than-10000-by-hououin__kyo-14ug | C++:\n\nvector<string> arr = {"0112344778","011237","0122579",\n"012356789","0124","0134449","0145678","01466788","0248",\n"0368888","0469","1","112234778","112 | Hououin__Kyouma | NORMAL | 2022-08-26T06:32:52.295426+00:00 | 2022-08-26T06:32:52.295541+00:00 | 219 | false | **C++:**\n```\nvector<string> arr = {"0112344778","011237","0122579",\n"012356789","0124","0134449","0145678","01466788","0248",\n"0368888","0469","1","112234778","11266777","122446",\n"125","128","1289","13468","16","2","224588","23","23334455",\n"234455668","23678","256","35566","4","46","8"};\nclass Solution {\npubl... | 4 | 0 | [] | 0 |
reordered-power-of-2 | Javascript | Easy to Understand | Fully explained | Power of 2 | Simple | javascript-easy-to-understand-fully-expl-vmei | \n//Main function\nvar reorderedPowerOf2 = function(n) {\n let arr = FindDigitMapArray(n);\n \n for(let i=0;i<31;i++){ //Till value of power of 2 is less tha | vivi13 | NORMAL | 2022-08-26T04:23:11.343974+00:00 | 2022-08-26T04:23:11.344028+00:00 | 420 | false | ```\n//Main function\nvar reorderedPowerOf2 = function(n) {\n let arr = FindDigitMapArray(n);\n \n for(let i=0;i<31;i++){ //Till value of power of 2 is less than 10^9 or 2^32 find all such power of 2\n let num = Math.pow(2,i);\n let twoArray = FindDigitMapArray(num);\n if(CheckTwoArraysAreEqual(arr,t... | 4 | 0 | ['JavaScript'] | 0 |
reordered-power-of-2 | Java | Sort | java-sort-by-student2091-wx9g | We can do the hash thing or we can also just sort it.\nI think sorting is easier. \nJava\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n | Student2091 | NORMAL | 2022-08-26T04:05:06.242104+00:00 | 2022-08-26T04:05:14.380802+00:00 | 830 | false | We can do the hash thing or we can also just sort it.\nI think sorting is easier. \n```Java\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n for (int i = 0; i <= 30; i++){\n char[] a = (""+(1<<i)).toCharArray();\n char[] b = (""+n).toCharArray();\n Arrays.sort(a... | 4 | 0 | ['Sorting', 'Java'] | 0 |
reordered-power-of-2 | C++ || Easy to Understand || Beginner Friendly | c-easy-to-understand-beginner-friendly-b-kb59 | \tbool check(string str)\n\t{\n\t\tint x = 0;\n\t\tfor(int i=0;i<str.size();i++)\n\t\t{\n\t\t\tx=x*10+(str[i]-\'0\');\n\t\t}\n\t\tint z = (x&(x-1));\n\t\tif(z== | viditgupta7001 | NORMAL | 2022-08-26T01:36:06.198883+00:00 | 2022-08-26T01:36:06.198924+00:00 | 415 | false | \tbool check(string str)\n\t{\n\t\tint x = 0;\n\t\tfor(int i=0;i<str.size();i++)\n\t\t{\n\t\t\tx=x*10+(str[i]-\'0\');\n\t\t}\n\t\tint z = (x&(x-1));\n\t\tif(z==0)return true;\n\t\treturn false;\n\t}\n\tvoid permute(string &str,int index,bool &ans)\n\t{\n\t\tif(index==str.size())\n\t\t{\n\t\t\tif(str[0]!=\'0\' && check(... | 4 | 0 | ['Backtracking', 'Bit Manipulation', 'Recursion', 'C'] | 1 |
reordered-power-of-2 | C++ Cool & Super Short, 100% faster 0ms | c-cool-super-short-100-faster-0ms-by-deb-pjv1 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) \n {\n static const set<string> pows {"1", "2", "4", "8", "16", "23", "46", "128", "256 | debbiealter | NORMAL | 2021-03-21T08:28:01.680819+00:00 | 2021-03-21T08:31:20.330602+00:00 | 210 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) \n {\n static const set<string> pows {"1", "2", "4", "8", "16", "23", "46", "128", "256", "125", "0124", "0248", "0469", "1289", "13468", "23678", "35566", "011237", "122446", "224588", "0145678", "0122579", "0134449", "0368888", "11266777", "2... | 4 | 2 | ['C'] | 3 |
reordered-power-of-2 | A Java solution which easy understand | a-java-solution-which-easy-understand-by-w705 | \nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int ans=1;ans<=Math.pow(10,9);ans*=2)\n if(equal(N,ans))\n | rosand | NORMAL | 2018-07-15T06:38:13.166075+00:00 | 2018-07-15T06:38:13.166075+00:00 | 408 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int ans=1;ans<=Math.pow(10,9);ans*=2)\n if(equal(N,ans))\n return true;\n return false;\n }\n public boolean equal(int num1,int num2){\n char[] str1 = Integer.toString(num1).toCharArray(),str2... | 4 | 0 | [] | 1 |
reordered-power-of-2 | Easy C++ code with explanation || BEATS 100% solutions. | easy-c-code-with-explanation-beats-100-s-57bi | Intuition\nThe problem requires checking if the digits of a number n can be rearranged to form a power of 2. The key insight is that two numbers have the same d | Ajay1112 | NORMAL | 2024-10-09T17:13:45.082647+00:00 | 2024-10-09T17:13:45.082769+00:00 | 216 | false | # Intuition\nThe problem requires checking if the digits of a number n can be rearranged to form a power of 2. The key insight is that two numbers have the same digit arrangement if their sorted digit strings are identical.\n\n# Approach\nConvert n to a string and sort its digits.\n\nPrecompute sorted powers of 2.\n\nG... | 3 | 0 | ['C++'] | 0 |
reordered-power-of-2 | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-mkmk | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n {\n if(n==1) return | shishirRsiam | NORMAL | 2024-05-15T07:30:57.188787+00:00 | 2024-05-15T07:31:56.790728+00:00 | 196 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n {\n if(n==1) return true;\n\n string target = to_string(n), temp;\n sort(target.begin(), target.end());\n for(int i=1;i<=32;i++)\n {\n l... | 3 | 0 | ['Hash Table', 'Math', 'Sorting', 'Counting', 'C++'] | 3 |
reordered-power-of-2 | Solution in C++ | solution-in-c-by-ashish_madhup-bvup | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ashish_madhup | NORMAL | 2023-02-26T16:36:47.608458+00:00 | 2023-02-26T16:36:47.608486+00:00 | 306 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 0 | ['C++'] | 0 |
reordered-power-of-2 | C++ Clear Solution with Explanation - Runtime: 0 ms, faster than 100.00% | c-clear-solution-with-explanation-runtim-78cm | 1.Brute force Approach: Find all possible combinations of numbers that can be formed from the Given Target number\'s digits and for each combination check if i | aviranjan444 | NORMAL | 2022-12-20T05:04:27.874901+00:00 | 2022-12-20T05:04:27.874943+00:00 | 893 | false | 1.**Brute force Approach:** Find all possible combinations of numbers that can be formed from the Given Target number\'s digits and for each combination check if it is a\n power of 2 or not . (Hint : Convert the number to string )\n 2. **Optimised/Efficient Approach:** We can see the constraint for n is *1 <= n <= 1... | 3 | 0 | ['Math', 'C', 'Counting'] | 2 |
reordered-power-of-2 | python short and precise answer | python-short-and-precise-answer-by-benon-h8a4 | ```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n for i in range(32):\n if Counter(str(n))==Counter(str(2**i)):\n | benon | NORMAL | 2022-08-26T19:17:24.614836+00:00 | 2022-08-26T19:17:24.614871+00:00 | 349 | false | ```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n for i in range(32):\n if Counter(str(n))==Counter(str(2**i)):\n return True\n return False\n | 3 | 0 | ['Python', 'Python3'] | 2 |
reordered-power-of-2 | EASY 6 line C++ code|| Beginner friendly || bitwise | easy-6-line-c-code-beginner-friendly-bit-n1w6 | class Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s=to_string(n);\n sort(s.begin(),s.end());\n do{\n if( s[0 | nematanya | NORMAL | 2022-08-26T14:40:15.970130+00:00 | 2022-08-26T14:43:13.934717+00:00 | 176 | false | class Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s=to_string(n);\n sort(s.begin(),s.end());\n do{\n if( s[0]==\'0\') continue;\n int k=stoi(s);\n if(!(k&k-1)) return true;\n }while(next_permutation(s.begin(),s.end()) );\n return ... | 3 | 0 | [] | 2 |
reordered-power-of-2 | Python || O(log(n)) time, O(1) space || Faster than 100% || Explained and compared | python-ologn-time-o1-space-faster-than-1-ez3f | Approach\nFor all the solutions presented here, the general approach is as follows:\n- Step #1: Identify the digits n is made of.\n- Step #2: Identify the power | RegInt | NORMAL | 2022-08-26T13:29:00.126595+00:00 | 2022-09-06T21:06:11.628757+00:00 | 253 | false | # Approach\nFor all the solutions presented here, the general approach is as follows:\n- **Step #1**: Identify the digits `n` is made of.\n- **Step #2**: Identify the powers of 2 that have the same number of digits as `n`; there are maximum four of them.\n- **Step #3**: Check whether any of the powers of 2 from step **... | 3 | 0 | ['Python', 'Python3'] | 0 |
reordered-power-of-2 | C++ || 10 4bit counters packet into 64bit integer || fast (0ms) | c-10-4bit-counters-packet-into-64bit-int-sgq7 | Please upvote if you like the solution, it motivates me to post more of them\n\nSolution 1: 10 4bit counters packet into a 64bit integer\n\nThis solution is bas | heder | NORMAL | 2022-08-26T08:44:39.188497+00:00 | 2022-08-26T18:04:20.636006+00:00 | 163 | false | **Please upvote if you like the solution, it motivates me to post more of them**\n\n**Solution 1: 10 4bit counters packet into a 64bit integer**\n\nThis solution is basically do a frequency count. Since any digit (0 to 9) is for sure less frequent than 16 in a 32bit integer we can use 4 bits to count the frequency the ... | 3 | 0 | ['Bit Manipulation', 'C'] | 0 |
reordered-power-of-2 | [JAVA] Simplest solution so far | NO bitwise | java-simplest-solution-so-far-no-bitwise-tlqn | \npublic boolean reorderedPowerOf2(int n) {\n char[] num = String.valueOf(n).toCharArray();\n Arrays.sort(num);\n for(int i=0;i<30;i++){\n | L_K_G | NORMAL | 2022-08-26T08:21:04.665521+00:00 | 2022-08-26T08:21:04.665563+00:00 | 260 | false | ```\npublic boolean reorderedPowerOf2(int n) {\n char[] num = String.valueOf(n).toCharArray();\n Arrays.sort(num);\n for(int i=0;i<30;i++){\n int intCur = (int)Math.pow(2,i);\n char[] charCur = String.valueOf(intCur).toCharArray();\n Arrays.sort(charCur);\n ... | 3 | 0 | ['Sorting', 'Java'] | 0 |
reordered-power-of-2 | Daily Challenge | C++ | 100% FASTER | EASY | HASHING | daily-challenge-c-100-faster-easy-hashin-qvx6 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n int arr[10];\n memset(arr,0,sizeof(arr));\n \n int x =n;\n | hritik_01478 | NORMAL | 2022-08-26T06:21:18.778314+00:00 | 2022-08-26T06:21:18.778347+00:00 | 110 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n int arr[10];\n memset(arr,0,sizeof(arr));\n \n int x =n;\n for(;x>0;){\n int rem = x%10;\n arr[rem]++;\n x = x/10;\n }\n for(int i=0; i<31; i++){\n int check... | 3 | 0 | ['C'] | 0 |
reordered-power-of-2 | C++||Easy understand|| | ceasy-understand-by-mickyt711ss-idqu | core concept\nWe can use 2147483648%numto determinenum is power of 2 or not.\nI hope this concept can help you~~~\nif you think this is useful, please upvoted i | mickyt711ss | NORMAL | 2022-08-26T05:49:12.410025+00:00 | 2022-08-26T05:52:10.268090+00:00 | 40 | false | # core concept\nWe can use `2147483648%num`to determine` num` is power of 2 or not.\nI hope this concept can help you~~~\nif you think this is useful, please upvoted it to let more people see this article.\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s=to_string(n);\n sort... | 3 | 0 | [] | 0 |
reordered-power-of-2 | Simple Cpp Solution | simple-cpp-solution-by-sanket_jadhav-a3c2 | ```\nclass Solution {\npublic:\n vector func(int n){\n vectorans(10);\n \n while(n){\n ans[n%10]++;\n n/=10;\n | Sanket_Jadhav | NORMAL | 2022-08-26T03:49:17.802501+00:00 | 2022-08-26T03:49:17.802539+00:00 | 47 | false | ```\nclass Solution {\npublic:\n vector<int> func(int n){\n vector<int>ans(10);\n \n while(n){\n ans[n%10]++;\n n/=10;\n }\n \n return ans;\n } \n \n bool reorderedPowerOf2(int n) {\n \n if((n&(n-1))==0)return true;\n ... | 3 | 0 | ['C++'] | 0 |
reordered-power-of-2 | c++ simple solution | c-simple-solution-by-pajju_0330-q4gu | Convert our given number to string (to_string())\n2. Sort it (sort())\n3. Compare it will all sorted string forms of 2 power numbers upto 30 ( 2^31 > 10^9)\n4 | Pajju_0330 | NORMAL | 2022-08-26T03:28:12.883376+00:00 | 2022-08-26T03:28:12.883419+00:00 | 77 | false | 1. Convert our given number to string (`to_string()`)\n2. Sort it (`sort()`)\n3. Compare it will all sorted string forms of 2 power numbers upto 30 ( 2^31 > 10^9)\n4. If equals to anyone return `true`\n5. else if no-match found return `false`\n\n**PLEASE UPVOTE IF YOU LIKED THIS \uD83D\uDE09\uD83D\uDE4C**\n\n\n\n\... | 3 | 0 | ['C', 'Sorting'] | 0 |
reordered-power-of-2 | SIMPLE C++ SOLUTION | simple-c-solution-by-lokeshthaduri1-1d7d | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n if(n == 1) return true;\n unordered_map<int, int> map;\n \n strin | lokeshthaduri1 | NORMAL | 2022-08-26T02:29:08.284004+00:00 | 2022-08-26T02:29:08.284035+00:00 | 798 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n if(n == 1) return true;\n unordered_map<int, int> map;\n \n string temp = to_string(n);\n for(int i = 0; i < temp.size(); i++){\n map[int(temp[i])-48]++;\n } \n \n int digits = temp.... | 3 | 1 | ['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 1 |
reordered-power-of-2 | Go | Golang Solution | go-golang-solution-by-d901203-ut6m | \nfunc reorderedPowerOf2(n int) bool {\n\tstr := strconv.Itoa(n)\n\tstrByte := []byte(str)\n\tsort.Slice(strByte, func(i, j int) bool { return strByte[i] < strB | d901203 | NORMAL | 2022-08-26T01:34:00.529877+00:00 | 2022-08-26T01:49:42.406387+00:00 | 129 | false | ```\nfunc reorderedPowerOf2(n int) bool {\n\tstr := strconv.Itoa(n)\n\tstrByte := []byte(str)\n\tsort.Slice(strByte, func(i, j int) bool { return strByte[i] < strByte[j] })\n\tfor i := 0; i < 31; i++ {\n\t\ttmp := strconv.Itoa(1 << i)\n\t\ttmpByte := []byte(tmp)\n\t\tsort.Slice(tmpByte, func(i, j int) bool { return tmp... | 3 | 0 | ['Go'] | 1 |
reordered-power-of-2 | [Java] [1ms][100% Faster] Compare Frequency with all powers of 2 | java-1ms100-faster-compare-frequency-wit-l3vs | \n\n\n\nclass Solution {\n\n public boolean reorderedPowerOf2(int n) {\n final int[] frequency = new int[10];\n int digitCount = 0;\n\n | java-lang-goutam | NORMAL | 2022-08-26T00:49:08.736145+00:00 | 2022-08-26T00:56:34.826882+00:00 | 267 | false | \n\n\n```\nclass Solution {\n\n public boolean reorderedPowerOf2(int n) {\n final int[] frequency = new int[10];\n int digitCount = 0;\n\n while (n > 0) {\n frequency[n % 10]+... | 3 | 2 | ['Bit Manipulation', 'Java'] | 0 |
reordered-power-of-2 | Track with Hashmap | Easy & Simple Solution | track-with-hashmap-easy-simple-solution-v35ha | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n vector<int> powers;\n for(int i=1;i<=1e9;i*=2){\n powers.push_back(i | sunny_38 | NORMAL | 2022-03-06T05:59:50.545011+00:00 | 2022-03-06T05:59:50.545041+00:00 | 56 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n vector<int> powers;\n for(int i=1;i<=1e9;i*=2){\n powers.push_back(i);\n }\n \n map<int,int> demand;\n while(n>0){\n demand[n%10]++;\n n/=10;\n }\n \n for... | 3 | 0 | [] | 0 |
reordered-power-of-2 | Easy to understand python solution. | easy-to-understand-python-solution-by-19-llq1 | ```\n\t\tl = sorted(list(str(n)))\n for i in range(30):\n a = 2**i\n b = sorted(list(str(a)))\n if l == b:\n | 1903480100017_A | NORMAL | 2021-12-07T19:07:18.552346+00:00 | 2021-12-07T19:07:18.552390+00:00 | 306 | false | ```\n\t\tl = sorted(list(str(n)))\n for i in range(30):\n a = 2**i\n b = sorted(list(str(a)))\n if l == b:\n return True\n | 3 | 0 | ['Python', 'Python3'] | 0 |
reordered-power-of-2 | Java || 1ms(97.25% faster) | java-1ms9725-faster-by-viking05-zc44 | Explanation\n1) Store the count of digits of given n in an array.\n2) Store the count of digits of every power of 2 from 1 to 30.\n3) If the count of digits in | viking05 | NORMAL | 2021-10-28T12:38:05.254965+00:00 | 2021-10-28T12:38:05.254991+00:00 | 107 | false | **Explanation**\n1) Store the count of digits of given n in an array.\n2) Store the count of digits of every power of 2 from 1 to 30.\n3) If the count of digits in any of the power of 2 matches with the count of digits of given n, then return true. \n4) If a match is not found after all iterations, that means the given... | 3 | 0 | [] | 1 |
reordered-power-of-2 | Java Simple and easy solution,1 ms, faster than 96.64%, T O(1), S O(1) clean code with comments. | java-simple-and-easy-solution1-ms-faster-u9s2 | PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\nclass Solution {\n //store all the power of 2 digits,\n //only do this operation 1 time\n static PowerOf | satyaDcoder | NORMAL | 2021-03-22T01:36:51.446487+00:00 | 2021-03-22T01:36:51.446529+00:00 | 342 | false | **PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n```\nclass Solution {\n //store all the power of 2 digits,\n //only do this operation 1 time\n static PowerOfTwo powerOfTwo = new PowerOfTwo();\n \n public boolean reorderedPowerOf2(int N) {\n String numDigit = String.valueOf(N);\n \n ... | 3 | 0 | ['Java'] | 0 |
reordered-power-of-2 | [C++/Python] Direct simulation & Indirect checking all possibilities of Power of 2 | cpython-direct-simulation-indirect-check-zam5 | Idea1: Direct simulation of Permutations [1]\nIntuition\n\nFor each permutation of the digits of N, let\'s check if that permutation is a power of 2.\n\nAlgori | codedayday | NORMAL | 2021-03-21T17:14:28.514980+00:00 | 2021-03-21T17:23:16.091217+00:00 | 150 | false | Idea1: Direct simulation of Permutations [1]\nIntuition\n\nFor each permutation of the digits of N, let\'s check if that permutation is a power of 2.\n\nAlgorithm\n\nThis approach has two steps: how will we generate the permutations of the digits, and how will we check that the permutation represents a power of 2?\n\n... | 3 | 0 | ['Bit Manipulation', 'C', 'Python'] | 1 |
reordered-power-of-2 | Reordered Power of 2 | Beats 100% | C++ | reordered-power-of-2-beats-100-c-by-shub-pxtt | The steps for solution to this problem are :\n Store all the powers of 2 in a vector\n Compare each numbner in vector with the given number to check if both hav | Shubh4nk | NORMAL | 2021-03-21T09:42:53.320691+00:00 | 2021-03-21T09:45:09.121577+00:00 | 147 | false | The steps for solution to this problem are :\n* Store all the powers of 2 in a vector\n* Compare each numbner in vector with the given number to check if both have same digits .\n* If both have same digits , return true\n* else return false .\nPls upvote if u feel it is correct and suggest if it can be improved .\n\n\n... | 3 | 0 | ['C'] | 0 |
reordered-power-of-2 | Rust counting solution | rust-counting-solution-by-sugyan-gff1 | rust\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n let digit_counts = |n: i32| -> [usize; 10] {\n let mut n = n;\n | sugyan | NORMAL | 2021-03-21T08:12:26.229592+00:00 | 2021-03-21T08:12:26.229623+00:00 | 90 | false | ```rust\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n let digit_counts = |n: i32| -> [usize; 10] {\n let mut n = n;\n let mut d = [0; 10];\n while n > 0 {\n d[(n % 10) as usize] += 1;\n n /= 10;\n }\n d\n ... | 3 | 0 | ['Rust'] | 0 |
reordered-power-of-2 | Python | python-by-gsan-r9sb | As N is bounded by 10^9 we need to check at most the 30-th power of 2. For each power of 2 we count the occurrence of every digit and store it in an array of si | gsan | NORMAL | 2021-03-21T07:16:26.965222+00:00 | 2021-03-21T07:16:26.965259+00:00 | 129 | false | As `N` is bounded by 10^9 we need to check at most the 30-th power of 2. For each power of 2 we count the occurrence of every digit and store it in an array of size 10 (from 0,...,9). If for any power of 2 the count matches that of `N` we return True. Else return False.\n\nTime: `O(1)`\nSpace: `O(1)`\n\n```python\nclas... | 3 | 0 | [] | 0 |
reordered-power-of-2 | Easy + Short + Understandable code in C++ || | easy-short-understandable-code-in-c-by-d-vpq6 | using compare function for removing 0 as first digit\n\nstatic bool com(char a,char b){\n return a>b;\n }\n bool reorderedPowerOf2(int N) {\n | darsh19 | NORMAL | 2020-12-21T18:16:30.408095+00:00 | 2020-12-21T18:16:30.408132+00:00 | 263 | false | #using compare function for removing 0 as first digit\n```\nstatic bool com(char a,char b){\n return a>b;\n }\n bool reorderedPowerOf2(int N) {\n string s= to_string(N);\n int n=s.size();\n int k=1;\n string p;\n sort(s.begin(),s.end(),com);\n while(n>=p.size())\n ... | 3 | 0 | ['C'] | 0 |
reordered-power-of-2 | Another 0ms C++ solution, No special data structure. | another-0ms-c-solution-no-special-data-s-0xfx | \n int myPow(int a) { // returns 10^a;\n if(!a) return 1;\n\n int res=1;\n while(a--)\n\t\t\t\tres *= 10;\n\n retur | mbanik | NORMAL | 2018-07-16T18:21:11.940584+00:00 | 2018-07-16T18:21:11.940584+00:00 | 314 | false | ```\n int myPow(int a) { // returns 10^a;\n if(!a) return 1;\n\n int res=1;\n while(a--)\n\t\t\t\tres *= 10;\n\n return res;\n }\n\n int counter(int N, int& c1 ) {\n int res = 0;\n\n for (; N; N /= 10) {res += myPow(N%10); c1++;}\n\n return res;\n ... | 3 | 1 | [] | 0 |
reordered-power-of-2 | [Python] easy to understand with explanation | python-easy-to-understand-with-explanati-h6tp | Since the leading digit is not zero, the reordered number shares the same number of digits with original one.\nThe search base can be greatly reduced.\nReturn t | rosaniline | NORMAL | 2018-07-15T04:53:57.976760+00:00 | 2018-07-15T04:53:57.976760+00:00 | 542 | false | Since the leading digit is not zero, the reordered number shares the same number of digits with original one.\nThe search base can be greatly reduced.\nReturn true if `Counter(N) == Counter(power of 2) and NumberOfDigits(N) == NumberOfDigits(power of 2)`\n\n```python\n def reorderedPowerOf2(self, N):\n from c... | 3 | 0 | [] | 2 |
reordered-power-of-2 | Rust | O(1) | 1ms | rust-o1-1ms-by-user7454af-7lcz | Intuition\nCheck if number has digits matching any power of two.\n\n# Approach\nTake digits of every power of two into an array, sort them and store them in a s | user7454af | NORMAL | 2024-06-29T22:40:20.126620+00:00 | 2024-06-29T22:40:20.126656+00:00 | 23 | false | # Intuition\nCheck if number has digits matching any power of two.\n\n# Approach\nTake digits of every power of two into an array, sort them and store them in a set. Then see if the digits array of given number is present in the set.\n\n# Complexity\n- Time complexity: $$O(1)$$\n\n- Space complexity: $$O(1)$$\n\n# Code... | 2 | 0 | ['Rust'] | 0 |
reordered-power-of-2 | Solution | solution-by-deleted_user-h2av | C++ []\nclass Solution {\n public:\n bool reorderedPowerOf2(int N) {\n int count = counter(N);\n\n for (int i = 0; i < 30; ++i)\n if (counter(1 << i | deleted_user | NORMAL | 2023-05-08T06:22:02.064193+00:00 | 2023-05-08T07:30:02.150498+00:00 | 513 | false | ```C++ []\nclass Solution {\n public:\n bool reorderedPowerOf2(int N) {\n int count = counter(N);\n\n for (int i = 0; i < 30; ++i)\n if (counter(1 << i) == count)\n return true;\n\n return false;\n }\n private:\n int counter(int n) {\n int count = 0;\n\n for (; n > 0; n /= 10)\n count... | 2 | 0 | ['C++', 'Java', 'Python3'] | 0 |
reordered-power-of-2 | C++ || short and 100% fast | c-short-and-100-fast-by-moj_leetcode-m4s9 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n)\n {\n string nn = to_string(n);\n \n sort(nn.begin(), nn.end());\n | moj_leetcode | NORMAL | 2023-03-26T12:32:13.275146+00:00 | 2023-03-26T12:32:13.275185+00:00 | 295 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n)\n {\n string nn = to_string(n);\n \n sort(nn.begin(), nn.end());\n \n for (int i = 0; i < 32; i++)\n {\n string pp = to_string(1 << i);\n \n sort(pp.begin(), pp.end());\n ... | 2 | 0 | [] | 0 |
reordered-power-of-2 | Js EASIEST to follow (One glance you will get it!). FASTEST. | js-easiest-to-follow-one-glance-you-will-lg07 | Have fun :)\n\n# Intuition\nhttps://onlinenumbertools.com/sort-digits\n\n\n# Code\n\nvar reorderedPowerOf2 = function (n) {\n const vals = new Set(["1","2","4" | hanbi58 | NORMAL | 2022-12-26T09:12:20.924558+00:00 | 2022-12-26T09:13:35.868900+00:00 | 179 | false | Have fun :)\n\n# Intuition\nhttps://onlinenumbertools.com/sort-digits\n\n\n# Code\n```\nvar reorderedPowerOf2 = function (n) {\n const vals = new Set(["1","2","4","8","16","23","46","128","256","125","0124","0248","0469","1289","13468","23678","35566","011237","122446","224588","0145678","0122579","0134449","0368888",... | 2 | 0 | ['JavaScript'] | 1 |
reordered-power-of-2 | Java 100% Faster | 1 ms solution | Explained | java-100-faster-1-ms-solution-explained-b2ntc | Approach\nExplanation.\n\nOccur is an 2d array which stores occurrences of all digits of each number (power of 2). \n\nExample: 2^16 = 65536, array with occuren | tbekpro | NORMAL | 2022-11-18T15:32:44.275369+00:00 | 2022-11-18T15:32:44.275405+00:00 | 687 | false | # Approach\nExplanation.\n\n**Occur** is an 2d array which stores occurrences of all digits of each number (power of 2). \n\nExample: 2^16 = 65536, array with occurences of digits for it will be: [0,0,0,1,0,2,2,0,0,0], because we have one occurence of 3, two occurences of 5, and two occurences of 6.\n\n**Occur** is $$s... | 2 | 0 | ['Java'] | 0 |
reordered-power-of-2 | c++ | easy | short | c-easy-short-by-venomhighs7-f3zx | \n\n# Code\n\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n\t\t\n v | venomhighs7 | NORMAL | 2022-11-06T04:21:31.268815+00:00 | 2022-11-06T04:21:31.268857+00:00 | 204 | false | \n\n# Code\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n\t\t\n vector<string> power;\n for(int i=0;i<=30;i++){\n int p = pow(2,i);\n power.push_back(to_string(p));\n }\n \n ... | 2 | 0 | ['C++'] | 0 |
reordered-power-of-2 | C++ || 100% fast || 0ms | c-100-fast-0ms-by-akshat0610-9w20 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n{\n string str = to_string(n);\n sort(str.begin(),str.end());\n long long int num;\n in | akshat0610 | NORMAL | 2022-10-29T09:07:35.036341+00:00 | 2022-10-29T09:07:35.036392+00:00 | 981 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n{\n string str = to_string(n);\n sort(str.begin(),str.end());\n long long int num;\n int counter=0;\n \n while(true)\n {\n num = pow(2,counter++);\n \n string temp = to_string(num);\n \n \n if(temp.length()>... | 2 | 0 | ['C', 'C++'] | 0 |
reordered-power-of-2 | Understanding Reordered Power of 2 in 3 Basic Steps | understanding-reordered-power-of-2-in-3-if0cf | I broke it down into 3 core parts:\n1. Identify individual digits of the number\n2. Identify valid permutations of the digits\n3. Test to see if a permutation i | vinniep79 | NORMAL | 2022-09-01T20:38:56.406151+00:00 | 2022-09-01T20:38:56.406185+00:00 | 45 | false | I broke it down into 3 core parts:\n1. Identify individual digits of the number\n2. Identify valid permutations of the digits\n3. Test to see if a permutation is a power of 2.\n\n**Step 1: Identify the Digits**\nIf I as a human see the number 1,024, I\'ll list the digits from left-to-right: 1, 0, 2, 4. But if I want... | 2 | 0 | [] | 1 |
reordered-power-of-2 | Simple Solution using Next Permutation to find the Answer | simple-solution-using-next-permutation-t-j8u1 | \nclass Solution {\npublic:\n vector<int> tovector(int n){\n vector<int> ans;\n while(n!=0){\n ans.push_back(n%10);\n n = | priyanshu2000 | NORMAL | 2022-08-26T18:57:06.299092+00:00 | 2022-08-26T18:57:06.299134+00:00 | 80 | false | ```\nclass Solution {\npublic:\n vector<int> tovector(int n){\n vector<int> ans;\n while(n!=0){\n ans.push_back(n%10);\n n = n/10;\n }\n sort(ans.begin(),ans.end());\n return ans;\n }\n // [5,2,1]\n \n int toInteger(vector<int> &ans){\n int ... | 2 | 0 | ['C', 'Sorting', 'C++'] | 1 |
reordered-power-of-2 | Ruby: Set of strings. | ruby-set-of-strings-by-user9697n-jl3m | Leetcode: 869. Reordered Power of 2.\n\n\nRuby: Set of strings.\n\n1. Need to get an array of powers of two till 10**9.\n2. Convert these numbers to strings and | user9697n | NORMAL | 2022-08-26T15:55:19.324652+00:00 | 2022-08-26T15:55:19.324696+00:00 | 23 | false | ## Leetcode: 869. Reordered Power of 2.\n\n\n**Ruby: Set of strings.**\n\n1. Need to get an array of powers of two till `10**9`.\n2. Convert these numbers to strings and sort chars. Create a set from the array.\n3. Convert inpur to string sort chars join and check does in include in the set.\n\nLet\'s try.\n\nRuby code... | 2 | 0 | ['Ordered Set', 'Ruby'] | 1 |
reordered-power-of-2 | [JAVA] Simple solution | java-simple-solution-by-priyankan_23-q9tf | \nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n char[] num = getArr(n);\n for (int i = 0; i < 30; ++i) {\n char[] p | priyankan_23 | NORMAL | 2022-08-26T15:40:07.187424+00:00 | 2022-08-26T15:40:07.187466+00:00 | 38 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n char[] num = getArr(n);\n for (int i = 0; i < 30; ++i) {\n char[] powerOfTwo = getArr(1 << i);\n if (Arrays.equals(num, powerOfTwo))\n return true;\n }\n return false;\n }\n\n pu... | 2 | 0 | [] | 0 |
reordered-power-of-2 | C++ 0ms Solution | Easy to understand | Short code | c-0ms-solution-easy-to-understand-short-jcq7c | 1) Create a vector of strings "v" of size 30 where each string represents a power of 2 (from 0 to 30) with its digits in sorted form.\n2) Convert the given numb | biswassougato | NORMAL | 2022-08-26T15:31:54.923236+00:00 | 2022-08-26T15:31:54.923266+00:00 | 51 | false | 1) Create a vector of strings "v" of size 30 where each string represents a power of 2 (from 0 to 30) with its digits in sorted form.\n2) Convert the given number to string "s" and sort its digits as well.\n3) Compare the resultant string "s" with each element of the vector of strings "v".\n4) Return true if a match is... | 2 | 0 | ['Math', 'String', 'C', 'Sorting'] | 0 |
reordered-power-of-2 | rust solution | rust-solution-by-radhikagokani-7ju9 | \n\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n\n let mut log = (n as f32).log2();\n if n == i32::pow(2, log as u32) {\n | radhikagokani | NORMAL | 2022-08-26T10:43:11.732361+00:00 | 2022-08-26T10:43:11.732396+00:00 | 19 | false | ```\n\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n\n let mut log = (n as f32).log2();\n if n == i32::pow(2, log as u32) {\n return true;\n }\n\n let mut n_s = n.to_string().chars().collect::<Vec<char>>();\n\n n_s.sort();\n\n for i in 0..30 {\n... | 2 | 0 | [] | 0 |
reordered-power-of-2 | [ Python ] ✅✅ Simple Python Solution Using Two Different Approach 🥳✌👍 | python-simple-python-solution-using-two-9fwdl | If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# 1. First Apporach Using Permutation Concept : \n# Runtime: 8288 | ashok_kumar_meghvanshi | NORMAL | 2022-08-26T10:10:05.247804+00:00 | 2022-08-26T10:48:20.368838+00:00 | 470 | false | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# 1. First Apporach Using Permutation Concept : \n# Runtime: 8288 ms, faster than 5.35% of Python3 online submissions for Reordered Power of 2.\n# Memory Usage: 28.1 MB, less than 11.23% of Python3 online submissions for Re... | 2 | 0 | ['Sorting', 'Probability and Statistics', 'Python', 'Python3'] | 1 |
reordered-power-of-2 | easy fast solution | easy-fast-solution-by-hurshidbek-atxp | \nPLEASE UPVOTE IF YOU LIKE\n\n```\n char[] car1 = ("" + n).toCharArray(); \n\t\tArrays.sort(car1);\n\n for(int i = 0; i < 30;i++){\n c | Hurshidbek | NORMAL | 2022-08-26T09:08:56.233879+00:00 | 2022-08-26T09:08:56.233920+00:00 | 135 | false | ```\nPLEASE UPVOTE IF YOU LIKE\n```\n```\n char[] car1 = ("" + n).toCharArray(); \n\t\tArrays.sort(car1);\n\n for(int i = 0; i < 30;i++){\n char[] car2 = ("" + (1 << i)).toCharArray(); \n\t\t\tArrays.sort(car2);\n if(Arrays.equals(car1, car2)) return true;\n }\n\n retur... | 2 | 0 | ['Bit Manipulation', 'Java'] | 0 |
reordered-power-of-2 | Asymptotic O(1) - Constant Time Solution || Faster than 100% || Explanation | asymptotic-o1-constant-time-solution-fas-6ucx | \nclass Solution { // 0ms - 100.00% Faster \n static HashSet<String> set;\n Solution(){ // this checks if the set is null, or it computes all the powers o | Lil_ToeTurtle | NORMAL | 2022-08-26T08:28:11.903121+00:00 | 2022-08-26T08:30:08.406658+00:00 | 127 | false | ```\nclass Solution { // 0ms - 100.00% Faster \n static HashSet<String> set;\n Solution(){ // this checks if the set is null, or it computes all the powers of 2 and stores it in the set(this operation occurs only once)\n if(set==null){\n set = new HashSet<String>();\n for(long i=1;i<=... | 2 | 0 | ['Ordered Set', 'Java'] | 2 |
reordered-power-of-2 | 100% Faster Solution | 100-faster-solution-by-archittt-tg3y | \n\nclass Solution {\npublic:\n\n bool equal(vector<int>&a,vector<int>&b ){\n for(int i=0;i<10;i++){\n if(a[i]!=b[i])return false;\n | archittt | NORMAL | 2022-08-26T07:26:06.853174+00:00 | 2022-08-30T11:51:45.194981+00:00 | 27 | false | \n```\nclass Solution {\npublic:\n\n bool equal(vector<int>&a,vector<int>&b ){\n for(int i=0;i<10;i++){\n if(a[i]!=b[i])return false;\n }\n return true;\n }\n vector<int> freq(int n){\n vector<int>f(10,0);\n while(n>0){\n f[n%10]++;\n n/=10;\n... | 2 | 0 | [] | 2 |
reordered-power-of-2 | Rust | Run-Time One-Liner and the Nerdiest Approach You Will Ever See :-P | With Comments | rust-run-time-one-liner-and-the-nerdiest-pize | So I wasn\'t the only one to think about precomputation here... Anyway, my "standard" solution is below, and then we\'ll go really crazy with an idea I had belo | wallicent | NORMAL | 2022-08-26T07:14:58.066546+00:00 | 2022-08-26T11:48:41.075864+00:00 | 54 | false | So I wasn\'t the only one to think about precomputation here... Anyway, my "standard" solution is below, and then we\'ll go really crazy with an idea I had below that, which you really don\'t want to miss :D.\n\nI love how easy it is to compute things at compile time in Rust compared to C++\'s `constexpr`. So for the "... | 2 | 0 | ['Rust'] | 0 |
reordered-power-of-2 | C++ || Python || Simple Fastest Solution || with Explanation | c-python-simple-fastest-solution-with-ex-02a2 | Idea:\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the c | bvian | NORMAL | 2022-08-26T06:47:22.102142+00:00 | 2022-08-26T06:47:22.102203+00:00 | 47 | false | **Idea:**\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the compare the result.\n\nIn that sense, the easiest solution here is to do exactly that: we can convert **N** to an array of its digits, sort it, then compare ... | 2 | 0 | ['C', 'Sorting', 'Python'] | 0 |
reordered-power-of-2 | ✅ Q869.C++ || 100% time & space || fast & easy | q869c-100-time-space-fast-easy-by-jayden-dv2h | C++ Code:\n\n bool isEqual(int arr1[10], int arr2[10]) {\n for (int i = 0; i < 10; i++) if (arr1[i] != arr2[i]) return 0;\n return 1;\n }\n\ | JaydenCh-0v0 | NORMAL | 2022-08-26T06:38:26.503622+00:00 | 2022-08-26T06:53:03.430401+00:00 | 123 | false | C++ Code:\n```\n bool isEqual(int arr1[10], int arr2[10]) {\n for (int i = 0; i < 10; i++) if (arr1[i] != arr2[i]) return 0;\n return 1;\n }\n\n int countDigits(int num, int digits[10]) {\n int cnt = 0;\n while (num > 0) digits[num % 10]++, num /= 10, cnt++;\n return cnt;\n ... | 2 | 0 | ['C', 'C++'] | 0 |
reordered-power-of-2 | 90% Tc and 78% SC python magic | 90-tc-and-78-sc-python-magic-by-nitanshr-y3aj | \ndef reorderedPowerOf2(self, n: int) -> bool:\n\tnum = set("".join(sorted(str(2**i))) for i in range(0, 32))\n\tn = \'\'.join(sorted(str(n)))\n\treturn n in nu | nitanshritulon | NORMAL | 2022-08-26T06:15:45.405046+00:00 | 2022-08-26T06:15:45.405089+00:00 | 101 | false | ```\ndef reorderedPowerOf2(self, n: int) -> bool:\n\tnum = set("".join(sorted(str(2**i))) for i in range(0, 32))\n\tn = \'\'.join(sorted(str(n)))\n\treturn n in num\n``` | 2 | 0 | ['Sorting', 'Python', 'Python3'] | 0 |
reordered-power-of-2 | C++ 100% Faster 0ms Solution by Hash | c-100-faster-0ms-solution-by-hash-by-nao-9i4v | Workaround\n\nAccording to the question, we need to reorder the target number n to indicate whether the number is power of 2. That is, the count of each digit i | naon | NORMAL | 2022-08-26T06:15:02.288574+00:00 | 2022-08-26T07:08:44.011284+00:00 | 99 | false | # **Workaround**\n\nAccording to the question, we need to reorder the target number `n` to indicate whether the number is power of 2. That is, the count of each digit in `n` must be same as the certain number which is power of 2. Therefore, we can use a custom hash function to count the digits:\n\n``` cpp\nint hashNumb... | 2 | 0 | ['C'] | 1 |
reordered-power-of-2 | c++ simple straight forward solution | c-simple-straight-forward-solution-by-ar-1npo | \nclass Solution {\npublic:\n bool checkdigits(int n,vector<int>&v)\n {\n vector<int>v1(10,-1);\n while(n)\n {\n v1[n%10]+ | arpitrathaur9 | NORMAL | 2022-08-26T05:58:01.896406+00:00 | 2022-08-26T05:58:01.896454+00:00 | 18 | false | ```\nclass Solution {\npublic:\n bool checkdigits(int n,vector<int>&v)\n {\n vector<int>v1(10,-1);\n while(n)\n {\n v1[n%10]++;\n n=n/10;\n }\n if(v1==v)\n return true;\n return false;\n }\n bool reorderedPowerOf2(int n) {\n v... | 2 | 0 | [] | 0 |
reordered-power-of-2 | ✅100% Faster || C++ Solution || Easy-understanding || Simple | 100-faster-c-solution-easy-understanding-g56o | \nclass Solution {\npublic:\n \n vector<int> gem(long int n) {\n vector<int>nums(10);\n \n while(n){\n nums[n%10]++;\n | StArK19 | NORMAL | 2022-08-26T05:47:00.289527+00:00 | 2022-08-26T05:47:00.289580+00:00 | 37 | false | ```\nclass Solution {\npublic:\n \n vector<int> gem(long int n) {\n vector<int>nums(10);\n \n while(n){\n nums[n%10]++;\n n=n/10;\n }\n return nums;\n }\n bool reorderedPowerOf2(int n) {\n vector<int>arr=gem(n);\n for(int i=0;i<31;i+... | 2 | 0 | ['C', 'C++'] | 0 |
reordered-power-of-2 | Approach: Converting into string, MAX TC: O(33*9*log(9)) i.e. O(1) constant time | approach-converting-into-string-max-tc-o-88k3 | \nclass Solution {\npublic:\n \n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n for(int i=0; | Niraj03 | NORMAL | 2022-08-26T05:45:00.048824+00:00 | 2022-09-02T03:51:30.585070+00:00 | 17 | false | ```\nclass Solution {\npublic:\n \n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n for(int i=0;i<33;i++){\n string x = to_string((long long)pow(2,i));\n sort(x.begin(),x.end());\n if(s==x){\n // cout<<s<<... | 2 | 0 | ['String', 'C'] | 0 |
reformat-the-string | C++ SIMPLE EASY WITH EXPLANATION | c-simple-easy-with-explanation-by-chase_-ehx3 | \nclass Solution {\npublic:\n string reformat(string s) {\n string a="",d="";\n // split string into alpha string and digit strings\n fo | chase_master_kohli | NORMAL | 2020-04-22T15:02:04.788771+00:00 | 2020-04-23T03:15:43.277479+00:00 | 5,008 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n string a="",d="";\n // split string into alpha string and digit strings\n for(auto x:s)\n isalpha(x)?a.push_back(x):d.push_back(x);\n \n // if difference is more than 1, return "" since not possible to reformat\n ... | 59 | 2 | [] | 4 |
reformat-the-string | [Python] Simple solution | python-simple-solution-by-katapan-lxmc | \n def reformat(self, s: str) -> str:\n a, b = [], []\n for c in s:\n if \'a\' <= c <= \'z\':\n a.append(c)\n | katapan | NORMAL | 2020-04-19T04:37:46.832331+00:00 | 2020-04-19T04:37:46.832379+00:00 | 4,697 | false | ```\n def reformat(self, s: str) -> str:\n a, b = [], []\n for c in s:\n if \'a\' <= c <= \'z\':\n a.append(c)\n else:\n b.append(c)\n if len(a) < len(b):\n a, b = b, a\n if len(a) - len(b) >= 2:\n return \'\'\n ... | 42 | 1 | [] | 8 |
reformat-the-string | python, fast (>99%) and very easy to read, detailed explanation with tips | python-fast-99-and-very-easy-to-read-det-i5v9 | \nclass Solution:\n def reformat(self, s: str) -> str:\n r,a,n = \'\',[],[]\n\t\t\n for c in list(s):\n if c.isalpha():\n | rmoskalenko | NORMAL | 2020-04-21T21:56:07.309459+00:00 | 2020-04-22T17:56:23.995534+00:00 | 1,986 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n r,a,n = \'\',[],[]\n\t\t\n for c in list(s):\n if c.isalpha():\n a.append(c)\n else:\n n.append(c)\n \n if abs(len(a)-len(n))<2:\n while a and n:\n ... | 35 | 0 | [] | 7 |
reformat-the-string | [Java] Use Character.isDigit() | java-use-characterisdigit-by-pwaykar-79ay | Understand the problem\n1. Reformat the string with alternate digit and character, and vice versa.\n2. Create 2 lists one for digits and the second one as chara | pwaykar | NORMAL | 2020-04-19T04:35:36.912773+00:00 | 2020-04-20T05:18:00.328820+00:00 | 4,116 | false | **Understand the problem**\n1. Reformat the string with alternate digit and character, and vice versa.\n2. Create 2 lists one for digits and the second one as characters\n3. Traverse the string and segregate the items to reformat\n4. Use a boolean to switch between character and digit and append all the items\n```\npub... | 30 | 3 | [] | 14 |
reformat-the-string | [Python] Clean solutions with explanation. O(N) Time and Space. | python-clean-solutions-with-explanation-30tsf | First we get lists of letters and digits seperately. \nThen we append the bigger list first. In this problem, i use flag to keep track of which one to append, t | jummyegg | NORMAL | 2020-04-19T06:53:16.614977+00:00 | 2020-04-19T07:11:09.174871+00:00 | 2,280 | false | First we get lists of letters and digits seperately. \nThen we append the bigger list first. In this problem, i use flag to keep track of which one to append, this will make the code cleaner.\n**1st Solution**\n```python\nclass Solution:\n def reformat(self, s: str) -> str:\n letters = [c for c in s if c.isal... | 20 | 1 | ['Python', 'Python3'] | 4 |
reformat-the-string | Java just count num of digits and letters | java-just-count-num-of-digits-and-letter-4axj | \npublic String reformat(String s) {\n if (s == null || s.length() == 0) return "";\n int ds = 0, as = 0;\n char[] arr = s.toCharArray(), r | hobiter | NORMAL | 2020-06-04T01:28:54.231563+00:00 | 2020-06-04T01:28:54.231598+00:00 | 1,603 | false | ```\npublic String reformat(String s) {\n if (s == null || s.length() == 0) return "";\n int ds = 0, as = 0;\n char[] arr = s.toCharArray(), res = new char[s.length()];\n for (char c : arr) {\n if (Character.isDigit(c)) ds++;\n else if (Character.isLetter(c)) as++;\n ... | 17 | 1 | [] | 4 |
reformat-the-string | [C++] Count and Display | c-count-and-display-by-orangezeit-wdd9 | Version 1\ncpp\nclass Solution {\npublic:\n string reformat(string s) {\n int c1(0), c2(0);\n unordered_map<char, int> cnts;\n \n | orangezeit | NORMAL | 2020-04-19T04:39:36.552050+00:00 | 2020-04-19T13:40:15.677916+00:00 | 1,583 | false | Version 1\n```cpp\nclass Solution {\npublic:\n string reformat(string s) {\n int c1(0), c2(0);\n unordered_map<char, int> cnts;\n \n for (const char& c: s) {\n isalpha(c) ? c1++ : c2++;\n cnts[c]++;\n }\n \n if (abs(c1 - c2) > 1) return "";\n ... | 10 | 1 | [] | 1 |
reformat-the-string | JavaScript O(n) simple solution | javascript-on-simple-solution-by-hon9g-j3wi | Time Complexity: O(n)\n- Space Complexity: O(n)\nJavaScript\n/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n let a = [], | hon9g | NORMAL | 2020-04-19T05:42:17.504887+00:00 | 2020-04-19T05:42:17.504920+00:00 | 676 | false | - Time Complexity: O(n)\n- Space Complexity: O(n)\n```JavaScript\n/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n let a = [], b = [];\n for (x of s) {\n isNaN(x) ? a.push(x) : b.push(x);\n }\n if (a.length < b.length) {\n [a, b] = [b, a];\n }\n return ... | 9 | 2 | ['JavaScript'] | 0 |
reformat-the-string | Why "leetcode" => "", but "j" => "j"?? | why-leetcode-but-j-j-by-votrubac-futm | I got 10 minutes penalty because of that. This problem was not tested properly.\n\nThey must have something like that in the OJ solution:\n\n\tif (s.size() <= 1 | votrubac | NORMAL | 2020-04-19T04:01:15.660636+00:00 | 2020-04-19T04:12:29.494700+00:00 | 674 | false | I got 10 minutes penalty because of that. This problem was not tested properly.\n\nThey must have something like that in the OJ solution:\n```\n\tif (s.size() <= 1)\n\t\treturn s;\n``` | 9 | 5 | [] | 7 |
reformat-the-string | Beats 100% of users with C++ || Using Add String Alternative Approach || Best Solution || | beats-100-of-users-with-c-using-add-stri-1clj | Intuition\n Describe your first thoughts on how to solve this problem. \n\nif you like the approach please upvote it\n\n\n\n\n\n\nif you like the approach pleas | abhirajpratapsingh | NORMAL | 2023-12-21T16:42:55.739650+00:00 | 2023-12-21T16:42:55.739692+00:00 | 426 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nif you like the approach please upvote it\n\n\n\n\n\n\nif you like the approach please upvote it\n\n\n# Approach\n<!-- Des... | 6 | 0 | ['String', 'C++'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.