mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 02:41:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,45 +1,36 @@
|
||||
<p>编写一个函数,输入是一个无符号整数(以二进制串的形式),返回其二进制表达式中数字位数为 '1' 的个数(也被称为<a href="https://baike.baidu.com/item/%E6%B1%89%E6%98%8E%E9%87%8D%E9%87%8F" target="_blank">汉明重量</a>)。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>请注意,在某些语言(如 Java)中,没有无符号整数类型。在这种情况下,输入和输出都将被指定为有符号整数类型,并且不应影响您的实现,因为无论整数是有符号的还是无符号的,其内部的二进制表示形式都是相同的。</li>
|
||||
<li>在 Java 中,编译器使用<a href="https://baike.baidu.com/item/二进制补码/5295284" target="_blank">二进制补码</a>记法来表示有符号整数。因此,在 <strong>示例 3</strong> 中,输入表示有符号整数 <code>-3</code>。</li>
|
||||
</ul>
|
||||
<p>给定一个正整数 <code>n</code>,编写一个函数,获取一个正整数的二进制形式并返回其二进制表达式中 <span data-keyword="set-bit">设置位</span> 的个数(也被称为<a href="https://baike.baidu.com/item/%E6%B1%89%E6%98%8E%E9%87%8D%E9%87%8F" target="_blank">汉明重量</a>)。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 00000000000000000000000000001011
|
||||
<strong>输入:</strong>n = 11
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>输入的二进制串 <code><strong>00000000000000000000000000001011</strong> 中,共有三位为 '1'。</code>
|
||||
<strong>解释:</strong>输入的二进制串 <code><strong>1011</strong> 中,共有 3 个设置位。</code>
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 00000000000000000000000010000000
|
||||
<strong>输入:</strong>n = 128
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>输入的二进制串 <strong>00000000000000000000000010000000</strong> 中,共有一位为 '1'。
|
||||
<strong>解释:</strong>输入的二进制串 <strong>10000000</strong> 中,共有 1 个设置位。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 11111111111111111111111111111101
|
||||
<strong>输出:</strong>31
|
||||
<strong>解释:</strong>输入的二进制串 <strong>11111111111111111111111111111101</strong> 中,共有 31 位为 '1'。</pre>
|
||||
<strong>输入:</strong>n = 2147483645
|
||||
<strong>输出:</strong>30
|
||||
<strong>解释:</strong>输入的二进制串 <strong>1111111111111111111111111111101</strong> 中,共有 30 个设置位。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>输入必须是长度为 <code>32</code> 的 <strong>二进制串</strong> 。</li>
|
||||
<li><code>1 <= n <= 2<sup>31</sup> - 1</code></li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
|
Reference in New Issue
Block a user