-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #692 from openset/develop
Add: new
- Loading branch information
Showing
32 changed files
with
490 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
problems/circular-permutation-in-binary-representation/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <[email protected]> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-positive-integer-solution-for-a-given-equation "Find Positive Integer Solution for a Given Equation") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/maximum-length-of-a-concatenated-string-with-unique-characters "Maximum Length of a Concatenated String with Unique Characters") | ||
|
||
## [1238. Circular Permutation in Binary Representation (Medium)](https://leetcode.com/problems/circular-permutation-in-binary-representation "循环码排列") | ||
|
||
<p>Given 2 integers <code>n</code> and <code>start</code>. Your task is return <strong>any</strong> permutation <code>p</code> of <code>(0,1,2.....,2^n -1) </code>such that :</p> | ||
|
||
<ul> | ||
<li><code>p[0] = start</code></li> | ||
<li><code>p[i]</code> and <code>p[i+1]</code> differ by only one bit in their binary representation.</li> | ||
<li><code>p[0]</code> and <code>p[2^n -1]</code> must also differ by only one bit in their binary representation.</li> | ||
</ul> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 2, start = 3 | ||
<strong>Output:</strong> [3,2,0,1] | ||
<strong>Explanation:</strong> The binary representation of the permutation is (11,10,00,01). | ||
All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 3, start = 2 | ||
<strong>Output:</strong> [2,6,7,5,4,0,1,3] | ||
<strong>Explanation:</strong> The binary representation of the permutation is (010,110,111,101,100,000,001,011). | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= n <= 16</code></li> | ||
<li><code>0 <= start < 2 ^ n</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Use gray code to generate a n-bit sequence. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Rotate the sequence such that its first element is start. | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
problems/find-positive-integer-solution-for-a-given-equation/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <[email protected]> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](https://github.com/openset/leetcode/tree/master/problems/web-crawler "Web Crawler") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/circular-permutation-in-binary-representation "Circular Permutation in Binary Representation") | ||
|
||
## [1237. Find Positive Integer Solution for a Given Equation (Easy)](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation "找出给定方程的正整数解") | ||
|
||
<p>Given a function <code>f(x, y)</code> and a value <code>z</code>, return all positive integer pairs <code>x</code> and <code>y</code> where <code>f(x,y) == z</code>.</p> | ||
|
||
<p>The function is constantly increasing, i.e.:</p> | ||
|
||
<ul> | ||
<li><code>f(x, y) < f(x + 1, y)</code></li> | ||
<li><code>f(x, y) < f(x, y + 1)</code></li> | ||
</ul> | ||
|
||
<p>The function interface is defined like this: </p> | ||
|
||
<pre> | ||
interface CustomFunction { | ||
public: | ||
// Returns positive integer f(x, y) for any given positive integer x and y. | ||
int f(int x, int y); | ||
}; | ||
</pre> | ||
|
||
<p>For custom testing purposes you're given an integer <code>function_id</code> and a target <code>z</code> as input, where <code>function_id</code> represent one function from an secret internal list, on the examples you'll know only two functions from the list. </p> | ||
|
||
<p>You may return the solutions in any order.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> function_id = 1, z = 5 | ||
<strong>Output:</strong> [[1,4],[2,3],[3,2],[4,1]] | ||
<strong>Explanation:</strong> function_id = 1 means that f(x, y) = x + y</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> function_id = 2, z = 5 | ||
<strong>Output:</strong> [[1,5],[5,1]] | ||
<strong>Explanation:</strong> function_id = 2 means that f(x, y) = x * y | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= function_id <= 9</code></li> | ||
<li><code>1 <= z <= 100</code></li> | ||
<li>It's guaranteed that the solutions of <code>f(x, y) == z</code> will be on the range <code>1 <= x, y <= 1000</code></li> | ||
<li>It's also guaranteed that <code>f(x, y)</code> will fit in 32 bit signed integer if <code>1 <= x, y <= 1000</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | ||
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Loop over 1 ≤ x,y ≤ 1000 and check if f(x,y) == z. | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
problems/maximum-length-of-a-concatenated-string-with-unique-characters/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <[email protected]> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](https://github.com/openset/leetcode/tree/master/problems/circular-permutation-in-binary-representation "Circular Permutation in Binary Representation") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/tiling-a-rectangle-with-the-fewest-squares "Tiling a Rectangle with the Fewest Squares") | ||
|
||
## [1239. Maximum Length of a Concatenated String with Unique Characters (Medium)](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters "串联字符串的最大长度") | ||
|
||
<p>Given an array of strings <code>arr</code>. String <code>s</code> is a concatenation of a sub-sequence of <code>arr</code> which have <strong>unique characters</strong>.</p> | ||
|
||
<p>Return <em>the maximum possible length</em> of <code>s</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> arr = ["un","iq","ue"] | ||
<strong>Output:</strong> 4 | ||
<strong>Explanation:</strong> All possible concatenations are "","un","iq","ue","uniq" and "ique". | ||
Maximum length is 4. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> arr = ["cha","r","act","ers"] | ||
<strong>Output:</strong> 6 | ||
<strong>Explanation:</strong> Possible solutions are "chaers" and "acters". | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> arr = ["abcdefghijklmnopqrstuvwxyz"] | ||
<strong>Output:</strong> 26 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= arr.length <= 16</code></li> | ||
<li><code>1 <= arr[i].length <= 26</code></li> | ||
<li><code>arr[i]</code> contains only lower case English letters.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] | ||
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
You can try all combinations and keep mask of characters you have. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
You can use DP. | ||
</details> |
Oops, something went wrong.