1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 06:51:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -6,13 +6,13 @@
"boundTopicId": null,
"title": "Broken Calculator",
"titleSlug": "broken-calculator",
"content": "<p>There is a broken calculator that has the integer <code>startValue</code> on its display initially. In one operation, you can:</p>\n\n<ul>\n\t<li>multiply the number on display by <code>2</code>, or</li>\n\t<li>subtract <code>1</code> from the number on display.</li>\n</ul>\n\n<p>Given two integers <code>startValue</code> and <code>target</code>, return <em>the minimum number of operations needed to display </em><code>target</code><em> on the calculator</em>.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> startValue = 2, target = 3\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Use double operation and then decrement operation {2 -&gt; 4 -&gt; 3}.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> startValue = 5, target = 8\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Use decrement and then double {5 -&gt; 4 -&gt; 8}.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> startValue = 3, target = 10\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> Use double, decrement and double {3 -&gt; 6 -&gt; 5 -&gt; 10}.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= x, y &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"content": "<p>There is a broken calculator that has the integer <code>startValue</code> on its display initially. In one operation, you can:</p>\n\n<ul>\n\t<li>multiply the number on display by <code>2</code>, or</li>\n\t<li>subtract <code>1</code> from the number on display.</li>\n</ul>\n\n<p>Given two integers <code>startValue</code> and <code>target</code>, return <em>the minimum number of operations needed to display </em><code>target</code><em> on the calculator</em>.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> startValue = 2, target = 3\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Use double operation and then decrement operation {2 -&gt; 4 -&gt; 3}.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> startValue = 5, target = 8\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Use decrement and then double {5 -&gt; 4 -&gt; 8}.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> startValue = 3, target = 10\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> Use double, decrement and double {3 -&gt; 6 -&gt; 5 -&gt; 10}.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= startValue, target &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 2235,
"dislikes": 185,
"likes": 2255,
"dislikes": 186,
"isLiked": null,
"similarQuestions": "[{\"title\": \"2 Keys Keyboard\", \"titleSlug\": \"2-keys-keyboard\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "2\n3\n5\n8\n3\n10",
@@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"84.5K\", \"totalSubmission\": \"156.2K\", \"totalAcceptedRaw\": 84542, \"totalSubmissionRaw\": 156209, \"acRate\": \"54.1%\"}",
"stats": "{\"totalAccepted\": \"85.6K\", \"totalSubmission\": \"158.1K\", \"totalAcceptedRaw\": 85604, \"totalSubmissionRaw\": 158051, \"acRate\": \"54.2%\"}",
"hints": [],
"solution": {
"id": "690",