Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1054">1054</span> | [Distant Barcodes](https://leetcode.com/problems/distant-barcodes "距离相等的条形码") | [Go](https://github.com/openset/leetcode/tree/master/problems/distant-barcodes) | Medium |
| <span id="1053">1053</span> | [Previous Permutation With One Swap](https://leetcode.com/problems/previous-permutation-with-one-swap "交换一次的先前排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/previous-permutation-with-one-swap) | Medium |
| <span id="1052">1052</span> | [Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner "爱生气的书店老板") | [Go](https://github.com/openset/leetcode/tree/master/problems/grumpy-bookstore-owner) | Medium |
| <span id="1051">1051</span> | [Height Checker](https://leetcode.com/problems/height-checker "高度检查器") | [Go](https://github.com/openset/leetcode/tree/master/problems/height-checker) | Easy |
| <span id="1050">1050</span> | [Actors and Directors Who Cooperated At Least Three Times](https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/actors-and-directors-who-cooperated-at-least-three-times) | Easy |
| <span id="1049">1049</span> | [Last Stone Weight II](https://leetcode.com/problems/last-stone-weight-ii "最后一块石头的重量 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight-ii) | Medium |
| <span id="1048">1048</span> | [Longest String Chain](https://leetcode.com/problems/longest-string-chain "最长字符串链") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-string-chain) | Medium |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< Previous](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight-ii "Last Stone Weight II")

Next >
[Next >](https://github.com/openset/leetcode/tree/master/problems/height-checker "Height Checker")

## 1050. Actors and Directors Who Cooperated At Least Three Times (Easy)

Expand Down
46 changes: 46 additions & 0 deletions problems/distant-barcodes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/previous-permutation-with-one-swap "Previous Permutation With One Swap")

Next >

## 1054. Distant Barcodes (Medium)

<p>In a warehouse, there is a row of barcodes, where the <code>i</code>-th barcode is&nbsp;<code>barcodes[i]</code>.</p>

<p>Rearrange the barcodes so that no two adjacent barcodes are equal.&nbsp; You may return any answer, and it is guaranteed an answer exists.</p>

<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<pre>
<strong>Input: </strong><span id="example-input-1-1">[1,1,1,2,2,2]</span>
<strong>Output: </strong><span id="example-output-1">[2,1,2,1,2,1]</span>
</pre>

<div>
<p><strong>Example 2:</strong></p>

<pre>
<strong>Input: </strong><span id="example-input-2-1">[1,1,1,1,2,2,3,3]</span>
<strong>Output: </strong><span id="example-output-2">[1,3,1,3,2,1,2,1]</span></pre>
</div>

<p>&nbsp;</p>

<p><strong>Note:</strong></p>

<ol>
<li><code>1 &lt;= barcodes.length &lt;= 10000</code></li>
<li><code>1 &lt;= barcodes[i] &lt;= 10000</code></li>
</ol>

<div>
<div>&nbsp;</div>
</div>
41 changes: 41 additions & 0 deletions problems/grumpy-bookstore-owner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/height-checker "Height Checker")

[Next >](https://github.com/openset/leetcode/tree/master/problems/previous-permutation-with-one-swap "Previous Permutation With One Swap")

## 1052. Grumpy Bookstore Owner (Medium)

<p>Today, the bookstore owner has a store open for <code>customers.length</code> minutes.&nbsp; Every minute, some number of customers (<code>customers[i]</code>) enter the store, and all those customers leave after the end of that minute.</p>

<p>On some minutes, the bookstore owner is grumpy.&nbsp; If the bookstore owner is grumpy on the i-th minute, <code>grumpy[i] = 1</code>, otherwise <code>grumpy[i] = 0</code>.&nbsp; When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.</p>

<p>The bookstore owner knows a secret technique to keep themselves&nbsp;not grumpy for <code>X</code>&nbsp;minutes straight, but can only use it once.</p>

<p>Return the maximum number of customers that can be satisfied throughout the day.</p>

<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<pre>
<strong>Input: </strong>customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3
<strong>Output: </strong>16
<strong>Explanation:</strong>&nbsp;The bookstore owner keeps themselves&nbsp;not grumpy for the last 3 minutes.
The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
</pre>

<p>&nbsp;</p>

<p><strong>Note:</strong></p>

<ul>
<li><code>1 &lt;= X &lt;=&nbsp;customers.length ==&nbsp;grumpy.length &lt;= 20000</code></li>
<li><code>0 &lt;=&nbsp;customers[i] &lt;= 1000</code></li>
<li><code>0 &lt;=&nbsp;grumpy[i] &lt;= 1</code></li>
</ul>
36 changes: 36 additions & 0 deletions problems/height-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/actors-and-directors-who-cooperated-at-least-three-times "Actors and Directors Who Cooperated At Least Three Times")

[Next >](https://github.com/openset/leetcode/tree/master/problems/grumpy-bookstore-owner "Grumpy Bookstore Owner")

## 1051. Height Checker (Easy)

<p>Students are asked to stand in non-decreasing order of heights for an annual photo.</p>

<p>Return the minimum number of students not standing in the right positions.&nbsp; (This is the number of students that must move in order for all students to be standing in non-decreasing order of height.)</p>

<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<pre>
<strong>Input: </strong>[1,1,4,2,1,3]
<strong>Output: </strong>3
<strong>Explanation: </strong>
Students with heights 4, 3 and the last 1 are not standing in the right positions.
</pre>

<p>&nbsp;</p>

<p><strong>Note:</strong></p>

<ol>
<li><code>1 &lt;= heights.length &lt;= 100</code></li>
<li><code>1 &lt;= heights[i] &lt;= 100</code></li>
</ol>
59 changes: 59 additions & 0 deletions problems/previous-permutation-with-one-swap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/grumpy-bookstore-owner "Grumpy Bookstore Owner")

[Next >](https://github.com/openset/leetcode/tree/master/problems/distant-barcodes "Distant Barcodes")

## 1053. Previous Permutation With One Swap (Medium)

<p>Given an array <code>A</code> of positive integers (not necessarily distinct), return the lexicographically largest permutation that is smaller than <code>A</code>, that can be <strong>made with one swap</strong> (A <em>swap</em> exchanges the positions of two numbers <code>A[i]</code> and <code>A[j]</code>).&nbsp; If it cannot be done, then return the same array.</p>

<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<pre>
<strong>Input: </strong>[3,2,1]
<strong>Output: </strong>[3,1,2]
<strong>Explanation: </strong>
Swapping 2 and 1.
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input: </strong>[1,1,5]
<strong>Output: </strong>[1,1,5]
<strong>Explanation: </strong>
This is already the smallest permutation.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input: </strong>[1,9,4,6,7]
<strong>Output: </strong>[1,7,4,6,9]
<strong>Explanation: </strong>
Swapping 9 and 7.
</pre>

<p><strong>Example 4:</strong></p>

<pre>
<strong>Input: </strong>[3,1,1,3]
<strong>Output: </strong>[1,1,3,3]
</pre>

<p>&nbsp;</p>

<p><strong>Note:</strong></p>

<ol>
<li><code>1 &lt;= A.length &lt;= 10000</code></li>
<li><code>1 &lt;= A[i] &lt;= 10000</code></li>
</ol>