Skip to content

Commit 3f88b4e

Browse files
committed
deploy: 0caf311
1 parent 075aa43 commit 3f88b4e

File tree

8 files changed

+330
-592
lines changed

8 files changed

+330
-592
lines changed

en/lc/340/index.html

Lines changed: 78 additions & 60 deletions
Large diffs are not rendered by default.

en/lc/341/index.html

Lines changed: 82 additions & 232 deletions
Large diffs are not rendered by default.

en/lc/342/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14154,9 +14154,9 @@
1415414154
<ul class="md-nav__list">
1415514155

1415614156
<li class="md-nav__item">
14157-
<a href="#solution-1" class="md-nav__link">
14157+
<a href="#solution-1-bit-manipulation" class="md-nav__link">
1415814158
<span class="md-ellipsis">
14159-
Solution 1
14159+
Solution 1: Bit Manipulation
1416014160
</span>
1416114161
</a>
1416214162

@@ -77352,7 +77352,10 @@ <h2 id="description">Description</h2>
7735277352
<h2 id="solutions">Solutions</h2>
7735377353
<!-- solution:start -->
7735477354

77355-
<h3 id="solution-1">Solution 1</h3>
77355+
<h3 id="solution-1-bit-manipulation">Solution 1: Bit Manipulation</h3>
77356+
<p>If a number is a power of 4, then it must be greater than $0$. Suppose this number is $4^x$, which is $2^{2x}$. Therefore, its binary representation has only one $1$, and this $1$ appears at an even position.</p>
77357+
<p>First, we check if the number is greater than $0$. Then, we verify if the number is $2^{2x}$ by checking if the bitwise AND of $n$ and $n-1$ is $0$. Finally, we check if the $1$ appears at an even position by verifying if the bitwise AND of $n$ and $\textit{0xAAAAAAAA}$ is $0$. If all three conditions are met, then the number is a power of 4.</p>
77358+
<p>The time complexity is $O(1)$, and the space complexity is $O(1)$.</p>
7735677359
<div class="tabbed-set tabbed-alternate" data-tabs="1:6"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label><label for="__tabbed_1_6">JavaScript</label></div>
7735777360
<div class="tabbed-content">
7735877361
<div class="tabbed-block">

en/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lc/340/index.html

Lines changed: 75 additions & 60 deletions
Large diffs are not rendered by default.

lc/341/index.html

Lines changed: 82 additions & 233 deletions
Large diffs are not rendered by default.

lc/342/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14196,7 +14196,7 @@
1419614196
<li class="md-nav__item">
1419714197
<a href="#_3" class="md-nav__link">
1419814198
<span class="md-ellipsis">
14199-
方法一
14199+
方法一:位运算
1420014200
</span>
1420114201
</a>
1420214202

@@ -81965,7 +81965,10 @@ <h2 id="_1">题目描述</h2>
8196581965
<h2 id="_2">解法</h2>
8196681966
<!-- solution:start -->
8196781967

81968-
<h3 id="_3">方法一</h3>
81968+
<h3 id="_3">方法一:位运算</h3>
81969+
<p>如果一个数是 4 的幂次方,那么这个数必须是大于 $0$ 的。不妨假设这个数是 $4^x$,即 $2^{2x}$,那么这个数的二进制表示中有且仅有一个 $1$,且这个 $1$ 出现在偶数位上。</p>
81970+
<p>因此,我们首先判断这个数是否大于 $0$,然后判断这个数是否是 $2^{2x}$,即 $n$ 与 $n-1$ 的按位与结果是否为 $0$,最后判断这个数的 $1$ 是否出现在偶数位上,即 $n$ 与 $\textit{0xAAAAAAAA}$ 的按位与结果是否为 $0$。如果这三个条件都满足,那么这个数就是 4 的幂次方。</p>
81971+
<p>时间复杂度 $O(1)$,空间复杂度 $O(1)$。</p>
8196981972
<div class="tabbed-set tabbed-alternate" data-tabs="1:6"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label><label for="__tabbed_1_6">JavaScript</label></div>
8197081973
<div class="tabbed-content">
8197181974
<div class="tabbed-block">

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)