1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-03 06:22:54 +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

@@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "2323",
"questionFrontendId": "6033",
"questionFrontendId": "2220",
"categoryTitle": "Algorithms",
"boundTopicId": 1385551,
"title": "Minimum Bit Flips to Convert Number",
@@ -12,13 +12,20 @@
"translatedContent": "<p>一次 <strong>位翻转</strong>&nbsp;定义为将数字&nbsp;<code>x</code>&nbsp;二进制中的一个位进行 <strong>翻转</strong>&nbsp;操作,即将&nbsp;<code>0</code>&nbsp;变成&nbsp;<code>1</code>&nbsp;,或者将&nbsp;<code>1</code>&nbsp;变成&nbsp;<code>0</code>&nbsp;。</p>\n\n<ul>\n\t<li>比方说,<code>x = 7</code>&nbsp;,二进制表示为&nbsp;<code>111</code>&nbsp;,我们可以选择任意一个位(包含没有显示的前导 0 )并进行翻转。比方说我们可以翻转最右边一位得到&nbsp;<code>110</code>&nbsp;,或者翻转右边起第二位得到&nbsp;<code>101</code>&nbsp;,或者翻转右边起第五位(这一位是前导 0 )得到&nbsp;<code>10111</code>&nbsp;等等。</li>\n</ul>\n\n<p>给你两个整数&nbsp;<code>start</code> 和&nbsp;<code>goal</code>&nbsp;,请你返回将&nbsp;<code>start</code>&nbsp;转变成&nbsp;<code>goal</code>&nbsp;的&nbsp;<strong>最少位翻转</strong>&nbsp;次数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<b>输入:</b>start = 10, goal = 7\n<b>输出:</b>3\n<b>解释:</b>10 和 7 的二进制表示分别为 1010 和 0111 。我们可以通过 3 步将 10 转变成 7 \n- 翻转右边起第一位得到101<strong><em>0</em></strong> -&gt; 101<strong><em>1 。</em></strong>\n- 翻转右边起第三位1<strong><em>0</em></strong>11 -&gt; 1<strong><em>1</em></strong>11 。\n- 翻转右边起第四位:<strong><em>1</em></strong>111 -&gt; <strong><em>0</em></strong>111 。\n我们无法在 3 步内将 10 转变成 7 。所以我们返回 3 。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<b>输入:</b>start = 3, goal = 4\n<b>输出:</b>3\n<b>解释:</b>3 和 4 的二进制表示分别为 011 和 100 。我们可以通过 3 步将 3 转变成 4 \n- 翻转右边起第一位01<strong><em>1</em></strong> -&gt; 01<em><strong>0 </strong></em>。\n- 翻转右边起第二位0<strong><em>1</em></strong>0 -&gt; 0<strong><em>0</em></strong>0 。\n- 翻转右边起第三位:<strong><em>0</em></strong>00 -&gt; <strong><em>1</em></strong>00 。\n我们无法在 3 步内将 3 变成 4 。所以我们返回 3 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>0 &lt;= start, goal &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 3,
"likes": 4,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Bit Manipulation",
"slug": "bit-manipulation",
"translatedName": "位运算",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@@ -130,7 +137,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"4.1K\", \"totalSubmission\": \"5K\", \"totalAcceptedRaw\": 4057, \"totalSubmissionRaw\": 4990, \"acRate\": \"81.3%\"}",
"stats": "{\"totalAccepted\": \"5.5K\", \"totalSubmission\": \"6.7K\", \"totalAcceptedRaw\": 5534, \"totalSubmissionRaw\": 6684, \"acRate\": \"82.8%\"}",
"hints": [
"If the value of a bit in start and goal differ, then we need to flip that bit.",
"Consider using the XOR operation to determine which bits need a bit flip."