Skip to content

Commit 115f1a0

Browse files
committed
test: [20250815] Add (342)
1 parent c92f05f commit 115f1a0

File tree

13 files changed

+189
-41
lines changed

13 files changed

+189
-41
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ members = [
287287
"problems/problems_2787",
288288
"problems/problems_326",
289289
"problems/problems_1780",
290+
"problems/problems_342",
290291
]
291292

292293
[package]
@@ -596,3 +597,4 @@ solution_2438 = { path = "problems/problems_2438", features = ["solution_2438"]
596597
solution_2787 = { path = "problems/problems_2787", features = ["solution_2787"] }
597598
solution_326 = { path = "problems/problems_326", features = ["solution_326"] }
598599
solution_1780 = { path = "problems/problems_1780", features = ["solution_1780"] }
600+
solution_342 = { path = "problems/problems_342", features = ["solution_342"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "1780",
2+
"daily": "342",
33
"plans": ["3628", "problems", "3629", "problems"]
44
}

golang/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
problem "leetCode/problems/problems_1780"
4+
problem "leetCode/problems/problems_342"
55
"testing"
66
)
77

88
func TestSolution(t *testing.T) {
9-
TestEach(t, "1780", "problems", problem.Solve)
9+
TestEach(t, "342", "problems", problem.Solve)
1010
}

problems/problems_342/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "solution_342"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 342 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_342 = []
12+
13+
[dependencies]
14+
serde_json = "1.0"
15+
rand = "0.8.4"
16+
regex = "1.10.5"
17+
library = { path = "../../rust/library", features = ["model"] }
18+
19+
[lib]
20+
name = "solution_342"
21+
path = "solution.rs"

problems/problems_342/Solution.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
5+
using namespace std;
6+
using json = nlohmann::json;
7+
8+
class Solution {
9+
public:
10+
bool isPowerOfFour(int n) {
11+
12+
}
13+
};
14+
15+
json leetcode::qubh::Solve(string input_json_values) {
16+
vector<string> inputArray;
17+
size_t pos = input_json_values.find('\n');
18+
while (pos != string::npos) {
19+
inputArray.push_back(input_json_values.substr(0, pos));
20+
input_json_values = input_json_values.substr(pos + 1);
21+
pos = input_json_values.find('\n');
22+
}
23+
inputArray.push_back(input_json_values);
24+
25+
Solution solution;
26+
int n = json::parse(inputArray.at(0));
27+
return solution.isPowerOfFour(n);
28+
}

problems/problems_342/Solution.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package problems.problems_342;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import java.util.*;
5+
import qubhjava.BaseSolution;
6+
7+
8+
public class Solution extends BaseSolution {
9+
public boolean isPowerOfFour(int n) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
int n = Integer.parseInt(inputJsonValues[0]);
16+
return JSON.toJSON(isPowerOfFour(n));
17+
}
18+
}

problems/problems_342/problem.md

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
1-
# 342. Power of Four
2-
3-
Given an integer `n`, return *`true` if it is a power of four. Otherwise, return `false`*.
4-
5-
An integer `n` is a power of four, if there exists an integer `x` such that n == 4<sup>x</sup>.
6-
7-
8-
9-
**Example 1:**
10-
11-
```
12-
Input: n = 16
13-
Output: true
14-
```
15-
16-
**Example 2:**
17-
18-
```
19-
Input: n = 5
20-
Output: false
21-
```
22-
23-
**Example 3:**
24-
25-
```
26-
Input: n = 1
27-
Output: true
28-
```
29-
30-
31-
32-
**Constraints:**
33-
34-
- -2<sup>31</sup> <= n <= 2<sup>31</sup> - 1
35-
36-
1+
# 342. Power of Four
2+
3+
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of four. Otherwise, return <code>false</code></em>.</p>
4+
5+
<p>An integer <code>n</code> is a power of four, if there exists an integer <code>x</code> such that <code>n == 4<sup>x</sup></code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
<pre><strong>Input:</strong> n = 16
10+
<strong>Output:</strong> true
11+
</pre><p><strong class="example">Example 2:</strong></p>
12+
<pre><strong>Input:</strong> n = 5
13+
<strong>Output:</strong> false
14+
</pre><p><strong class="example">Example 3:</strong></p>
15+
<pre><strong>Input:</strong> n = 1
16+
<strong>Output:</strong> true
17+
</pre>
18+
<p>&nbsp;</p>
19+
<p><strong>Constraints:</strong></p>
20+
21+
<ul>
22+
<li><code>-2<sup>31</sup> &lt;= n &lt;= 2<sup>31</sup> - 1</code></li>
23+
</ul>
24+
25+
<p>&nbsp;</p>
26+
<strong>Follow up:</strong> Could you solve it without loops/recursion?

problems/problems_342/problem_zh.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 342. 4的幂
2+
3+
<p>给定一个整数,写一个函数来判断它是否是 4 的幂次方。如果是,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p>
4+
5+
<p>整数 <code>n</code> 是 4 的幂次方需满足:存在整数 <code>x</code> 使得 <code>n == 4<sup>x</sup></code></p>
6+
7+
<p>&nbsp;</p>
8+
9+
<p><strong>示例 1:</strong></p>
10+
11+
<pre>
12+
<strong>输入:</strong>n = 16
13+
<strong>输出:</strong>true
14+
</pre>
15+
16+
<p><strong>示例 2:</strong></p>
17+
18+
<pre>
19+
<strong>输入:</strong>n = 5
20+
<strong>输出:</strong>false
21+
</pre>
22+
23+
<p><strong>示例 3:</strong></p>
24+
25+
<pre>
26+
<strong>输入:</strong>n = 1
27+
<strong>输出:</strong>true
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
32+
<p><strong>提示:</strong></p>
33+
34+
<ul>
35+
<li><code>-2<sup>31</sup> &lt;= n &lt;= 2<sup>31</sup> - 1</code></li>
36+
</ul>
37+
38+
<p>&nbsp;</p>
39+
40+
<p><strong>进阶:</strong>你能不使用循环或者递归来完成本题吗?</p>

problems/problems_342/solution.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package problem342
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func isPowerOfFour(n int) bool {
10+
11+
}
12+
13+
func Solve(inputJsonValues string) any {
14+
inputValues := strings.Split(inputJsonValues, "\n")
15+
var n int
16+
17+
if err := json.Unmarshal([]byte(inputValues[0]), &n); err != nil {
18+
log.Fatal(err)
19+
}
20+
21+
return isPowerOfFour(n)
22+
}

problems/problems_342/solution.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use serde_json::{json, Value};
2+
3+
pub struct Solution;
4+
5+
impl Solution {
6+
pub fn is_power_of_four(n: i32) -> bool {
7+
8+
}
9+
}
10+
11+
#[cfg(feature = "solution_342")]
12+
pub fn solve(input_string: String) -> Value {
13+
let input_values: Vec<String> = input_string.split('\n').map(|x| x.to_string()).collect();
14+
let n: i32 = serde_json::from_str(&input_values[0]).expect("Failed to parse input");
15+
json!(Solution::is_power_of_four(n))
16+
}

0 commit comments

Comments
 (0)