Skip to content

Commit 85ed312

Browse files
committed
test: [20260501] Add (396)
1 parent 9ad2a71 commit 85ed312

15 files changed

Lines changed: 236 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ members = [
546546
"problems/problems_2033",
547547
"problems/problems_3225",
548548
"problems/problems_3742",
549+
"problems/problems_396",
549550
]
550551

551552
[package]
@@ -1114,3 +1115,4 @@ solution_1391 = { path = "problems/problems_1391", features = ["solution_1391"]
11141115
solution_2033 = { path = "problems/problems_2033", features = ["solution_2033"] }
11151116
solution_3225 = { path = "problems/problems_3225", features = ["solution_3225"] }
11161117
solution_3742 = { path = "problems/problems_3742", features = ["solution_3742"] }
1118+
solution_396 = { path = "problems/problems_396", features = ["solution_396"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "3742",
2+
"daily": "396",
33
"plans": ["3833", "problems", "3834", "problems", "3835", "problems", "3836", "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_3742"
4+
problem "leetCode/problems/problems_396"
55
"testing"
66
)
77

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

problems/problems_396/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_396"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 396 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_396 = []
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_396"
21+
path = "solution.rs"

problems/problems_396/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+
int maxRotateFunction(vector<int>& nums) {
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+
vector<int> nums = json::parse(inputArray.at(0));
27+
return solution.maxRotateFunction(nums);
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package problems.problems_396;
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 int maxRotateFunction(int[] nums) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
int[] nums = jsonArrayToIntArray(inputJsonValues[0]);
16+
return JSON.toJSON(maxRotateFunction(nums));
17+
}
18+
}

problems/problems_396/problem.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 396. Rotate Function
2+
3+
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p>
4+
5+
<p>Assume <code>arr<sub>k</sub></code> to be an array obtained by rotating <code>nums</code> by <code>k</code> positions clock-wise. We define the <strong>rotation function</strong> <code>F</code> on <code>nums</code> as follow:</p>
6+
7+
<ul>
8+
<li><code>F(k) = 0 * arr<sub>k</sub>[0] + 1 * arr<sub>k</sub>[1] + ... + (n - 1) * arr<sub>k</sub>[n - 1].</code></li>
9+
</ul>
10+
11+
<p>Return <em>the maximum value of</em> <code>F(0), F(1), ..., F(n-1)</code>.</p>
12+
13+
<p>The test cases are generated so that the answer fits in a <strong>32-bit</strong> integer.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> nums = [4,3,2,6]
20+
<strong>Output:</strong> 26
21+
<strong>Explanation:</strong>
22+
F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25
23+
F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16
24+
F(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23
25+
F(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26
26+
So the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.
27+
</pre>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums = [100]
33+
<strong>Output:</strong> 0
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>n == nums.length</code></li>
41+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
42+
<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
43+
</ul>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 396. 旋转函数
2+
3+
<p>给定一个长度为 <code>n</code> 的整数数组&nbsp;<code>nums</code>&nbsp;。</p>
4+
5+
<p>假设&nbsp;<code>arr<sub>k</sub></code>&nbsp;是数组&nbsp;<code>nums</code>&nbsp;顺时针旋转 <code>k</code> 个位置后的数组,我们定义&nbsp;<code>nums</code>&nbsp;的 <strong>旋转函数</strong>&nbsp;&nbsp;<code>F</code>&nbsp;为:</p>
6+
7+
<ul>
8+
<li><code>F(k) = 0 * arr<sub>k</sub>[0] + 1 * arr<sub>k</sub>[1] + ... + (n - 1) * arr<sub>k</sub>[n - 1]</code></li>
9+
</ul>
10+
11+
<p>返回&nbsp;<em><code>F(0), F(1), ..., F(n-1)</code>中的最大值&nbsp;</em>。</p>
12+
13+
<p>生成的测试用例让答案符合&nbsp;<strong>32 位</strong> 整数。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong> nums = [4,3,2,6]
21+
<strong>输出:</strong> 26
22+
<strong>解释:</strong>
23+
F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25
24+
F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16
25+
F(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23
26+
F(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26
27+
所以 F(0), F(1), F(2), F(3) 中的最大值是 F(3) = 26 。
28+
</pre>
29+
30+
<p><strong>示例 2:</strong></p>
31+
32+
<pre>
33+
<strong>输入:</strong> nums = [100]
34+
<strong>输出:</strong> 0
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
39+
<p><strong>提示:</strong></p>
40+
41+
<ul>
42+
<li><code>n == nums.length</code></li>
43+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
44+
<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
45+
</ul>

problems/problems_396/solution.go

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

problems/problems_396/solution.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import solution
2+
from typing import *
3+
4+
5+
class Solution(solution.Solution):
6+
def solve(self, test_input=None):
7+
return self.maxRotateFunction(test_input)
8+
9+
def maxRotateFunction(self, nums: List[int]) -> int:
10+
pass
11+

0 commit comments

Comments
 (0)