Skip to content

Commit c8f4a32

Browse files
committed
test: [20250824] Add (1493)
1 parent a3d7c92 commit c8f4a32

File tree

15 files changed

+226
-5
lines changed

15 files changed

+226
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ members = [
296296
"problems/problems_1504",
297297
"problems/problems_3195",
298298
"problems/problems_3197",
299+
"problems/problems_1493",
299300
]
300301

301302
[package]
@@ -614,3 +615,4 @@ solution_1277 = { path = "problems/problems_1277", features = ["solution_1277"]
614615
solution_1504 = { path = "problems/problems_1504", features = ["solution_1504"] }
615616
solution_3195 = { path = "problems/problems_3195", features = ["solution_3195"] }
616617
solution_3197 = { path = "problems/problems_3197", features = ["solution_3197"] }
618+
solution_1493 = { path = "problems/problems_1493", features = ["solution_1493"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "3197",
2+
"daily": "1493",
33
"plans": ["3652", "problems", "3653", "problems", "3654", "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_3197"
4+
problem "leetCode/problems/problems_1493"
55
"testing"
66
)
77

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

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

problems/problems_1493/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 longestSubarray(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.longestSubarray(nums);
28+
}

problems/problems_1493/Solution.java

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

problems/problems_1493/problem.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 1493. Longest Subarray of 1's After Deleting One Element [Rating: 1423.04]
2+
3+
<p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
4+
5+
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>&#39;s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> nums = [1,1,0,1]
12+
<strong>Output:</strong> 3
13+
<strong>Explanation:</strong> After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1&#39;s.
14+
</pre>
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> nums = [0,1,1,1,0,1,1,0,1]
20+
<strong>Output:</strong> 5
21+
<strong>Explanation:</strong> After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1&#39;s is [1,1,1,1,1].
22+
</pre>
23+
24+
<p><strong class="example">Example 3:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> nums = [1,1,1]
28+
<strong>Output:</strong> 2
29+
<strong>Explanation:</strong> You must delete one element.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
37+
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
38+
</ul>

problems/problems_1493/problem_zh.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 1493. 删掉一个元素以后全为 1 的最长子数组 [难度分: 1423.04]
2+
3+
<p>给你一个二进制数组&nbsp;<code>nums</code>&nbsp;,你需要从中删掉一个元素。</p>
4+
5+
<p>请你在删掉元素的结果数组中,返回最长的且只包含 1 的非空子数组的长度。</p>
6+
7+
<p>如果不存在这样的子数组,请返回 0 。</p>
8+
9+
<p>&nbsp;</p>
10+
11+
<p><strong>提示 1:</strong></p>
12+
13+
<pre>
14+
<strong>输入:</strong>nums = [1,1,0,1]
15+
<strong>输出:</strong>3
16+
<strong>解释:</strong>删掉位置 2 的数后,[1,1,1] 包含 3 个 1 。</pre>
17+
18+
<p><strong>示例 2:</strong></p>
19+
20+
<pre>
21+
<strong>输入:</strong>nums = [0,1,1,1,0,1,1,0,1]
22+
<strong>输出:</strong>5
23+
<strong>解释:</strong>删掉位置 4 的数字后,[0,1,1,1,1,1,0,1] 的最长全 1 子数组为 [1,1,1,1,1] 。</pre>
24+
25+
<p><strong>示例 3:</strong></p>
26+
27+
<pre>
28+
<strong>输入:</strong>nums = [1,1,1]
29+
<strong>输出:</strong>2
30+
<strong>解释:</strong>你必须要删除一个元素。</pre>
31+
32+
<p>&nbsp;</p>
33+
34+
<p><strong>提示:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
38+
<li><code>nums[i]</code>&nbsp;要么是&nbsp;<code>0</code>&nbsp;要么是&nbsp;<code>1</code> 。</li>
39+
</ul>

problems/problems_1493/solution.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package problem1493
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func longestSubarray(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 longestSubarray(nums)
22+
}

problems/problems_1493/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.longestSubarray(test_input)
8+
9+
def longestSubarray(self, nums: List[int]) -> int:
10+
pass
11+

0 commit comments

Comments
 (0)