Skip to content

Commit 1484369

Browse files
committed
test: 3612, 3613, 3614, 3615 solution
py, c++, go, java
1 parent 67e1590 commit 1484369

35 files changed

+1889
-18
lines changed

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"daily": "2410",
3-
"plans": ["3602", "problems", "3603", "problems", "3604", "problems", "3605", "problems", "3606", "problems", "3607", "problems", "3608", "problems", "3609", "problems"]
3+
"plans": ["3612", "problems", "3613", "problems", "3614", "problems", "3615", "problems"]
44
}

golang/problems_test.go

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

33
import (
4-
"leetCode/problems/problems_3602"
5-
"leetCode/problems/problems_3603"
6-
"leetCode/problems/problems_3604"
7-
"leetCode/problems/problems_3605"
8-
"leetCode/problems/problems_3606"
9-
"leetCode/problems/problems_3607"
10-
"leetCode/problems/problems_3608"
11-
"leetCode/problems/problems_3609"
4+
problem3612 "leetCode/problems/problems_3612"
5+
problem3613 "leetCode/problems/problems_3613"
6+
problem3614 "leetCode/problems/problems_3614"
7+
problem3615 "leetCode/problems/problems_3615"
128
"testing"
139
)
1410

1511
func TestSolutions(t *testing.T) {
16-
TestEach(t, "3602", "problems", problem3602.Solve)
17-
TestEach(t, "3603", "problems", problem3603.Solve)
18-
TestEach(t, "3604", "problems", problem3604.Solve)
19-
TestEach(t, "3605", "problems", problem3605.Solve)
20-
TestEach(t, "3606", "problems", problem3606.Solve)
21-
TestEach(t, "3607", "problems", problem3607.Solve)
22-
TestEach(t, "3608", "problems", problem3608.Solve)
23-
TestEach(t, "3609", "problems", problem3609.Solve)
12+
TestEach(t, "3612", "problems", problem3612.Solve)
13+
TestEach(t, "3613", "problems", problem3613.Solve)
14+
TestEach(t, "3614", "problems", problem3614.Solve)
15+
TestEach(t, "3615", "problems", problem3615.Solve)
2416
}

problems/problems_3606/testcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self):
1313
self.testcases.append(case(
1414
Input=[["GROCERY15", "ELECTRONICS_50", "DISCOUNT10"], ["grocery", "electronics", "invalid"],
1515
[False, True, True]], Output=['ELECTRONICS_50']))
16-
self.testcases.append(case(Input=[["1OFw","0MvB"],["electronics","pharmacy"],[True,True]], Output=["1OFw","0MvB"]))
16+
self.testcases.append(case(Input=[["1OFw","0MvB"],["electronics","pharmacy"],[True,True]], Output=["1OFw","0MvB"]))
1717

1818
def get_testcases(self):
1919
return self.testcases

problems/problems_3612/Solution.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
using namespace std;
5+
using json = nlohmann::json;
6+
7+
class Solution {
8+
public:
9+
string processStr(const string &s) {
10+
string result;
11+
for (char c : s) {
12+
if (c == '#') {
13+
result += result;
14+
} else if (c == '%') {
15+
reverse(result.begin(), result.end());
16+
} else if (c == '*') {
17+
if (!result.empty()) {
18+
result.pop_back();
19+
}
20+
} else {
21+
result += c;
22+
}
23+
}
24+
return result;
25+
}
26+
};
27+
28+
json leetcode::qubh::Solve(string input_json_values) {
29+
vector<string> inputArray;
30+
size_t pos = input_json_values.find('\n');
31+
while (pos != string::npos) {
32+
inputArray.push_back(input_json_values.substr(0, pos));
33+
input_json_values = input_json_values.substr(pos + 1);
34+
pos = input_json_values.find('\n');
35+
}
36+
inputArray.push_back(input_json_values);
37+
38+
Solution solution;
39+
string s = json::parse(inputArray.at(0));
40+
return solution.processStr(s);
41+
}

problems/problems_3612/Solution.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package problems.problems_3612;
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 String processStr(String s) {
10+
StringBuilder sb = new StringBuilder();
11+
for (char c: s.toCharArray()) {
12+
switch (c) {
13+
case '#':
14+
sb.append(sb);
15+
break;
16+
case '%':
17+
sb.reverse();
18+
break;
19+
case '*':
20+
if (!sb.isEmpty()) {
21+
sb.deleteCharAt(sb.length() - 1);
22+
}
23+
break;
24+
default:
25+
sb.append(c);
26+
}
27+
}
28+
return sb.toString();
29+
}
30+
31+
@Override
32+
public Object solve(String[] inputJsonValues) {
33+
String s = jsonStringToString(inputJsonValues[0]);
34+
return JSON.toJSON(processStr(s));
35+
}
36+
}

problems/problems_3612/problem.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# 3612. Process String with Special Operations I
2+
3+
<p>You are given a string <code>s</code> consisting of lowercase English letters and the special characters: <code>*</code>, <code>#</code>, and <code>%</code>.</p>
4+
5+
<p>Build a new string <code>result</code> by processing <code>s</code> according to the following rules from left to right:</p>
6+
7+
<ul>
8+
<li>If the letter is a <strong>lowercase</strong> English letter append it to <code>result</code>.</li>
9+
<li>A <code>&#39;*&#39;</code> <strong>removes</strong> the last character from <code>result</code>, if it exists.</li>
10+
<li>A <code>&#39;#&#39;</code> <strong>duplicates</strong> the current <code>result</code> and <strong>appends</strong> it to itself.</li>
11+
<li>A <code>&#39;%&#39;</code> <strong>reverses</strong> the current <code>result</code>.</li>
12+
</ul>
13+
14+
<p>Return the final string <code>result</code> after processing all characters in <code>s</code>.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong class="example">Example 1:</strong></p>
18+
19+
<div class="example-block">
20+
<p><strong>Input:</strong> <span class="example-io">s = &quot;a#b%*&quot;</span></p>
21+
22+
<p><strong>Output:</strong> <span class="example-io">&quot;ba&quot;</span></p>
23+
24+
<p><strong>Explanation:</strong></p>
25+
26+
<table style="border: 1px solid black;">
27+
<thead>
28+
<tr>
29+
<th style="border: 1px solid black;"><code>i</code></th>
30+
<th style="border: 1px solid black;"><code>s[i]</code></th>
31+
<th style="border: 1px solid black;">Operation</th>
32+
<th style="border: 1px solid black;">Current <code>result</code></th>
33+
</tr>
34+
</thead>
35+
<tbody>
36+
<tr>
37+
<td style="border: 1px solid black;">0</td>
38+
<td style="border: 1px solid black;"><code>&#39;a&#39;</code></td>
39+
<td style="border: 1px solid black;">Append <code>&#39;a&#39;</code></td>
40+
<td style="border: 1px solid black;"><code>&quot;a&quot;</code></td>
41+
</tr>
42+
<tr>
43+
<td style="border: 1px solid black;">1</td>
44+
<td style="border: 1px solid black;"><code>&#39;#&#39;</code></td>
45+
<td style="border: 1px solid black;">Duplicate <code>result</code></td>
46+
<td style="border: 1px solid black;"><code>&quot;aa&quot;</code></td>
47+
</tr>
48+
<tr>
49+
<td style="border: 1px solid black;">2</td>
50+
<td style="border: 1px solid black;"><code>&#39;b&#39;</code></td>
51+
<td style="border: 1px solid black;">Append <code>&#39;b&#39;</code></td>
52+
<td style="border: 1px solid black;"><code>&quot;aab&quot;</code></td>
53+
</tr>
54+
<tr>
55+
<td style="border: 1px solid black;">3</td>
56+
<td style="border: 1px solid black;"><code>&#39;%&#39;</code></td>
57+
<td style="border: 1px solid black;">Reverse <code>result</code></td>
58+
<td style="border: 1px solid black;"><code>&quot;baa&quot;</code></td>
59+
</tr>
60+
<tr>
61+
<td style="border: 1px solid black;">4</td>
62+
<td style="border: 1px solid black;"><code>&#39;*&#39;</code></td>
63+
<td style="border: 1px solid black;">Remove the last character</td>
64+
<td style="border: 1px solid black;"><code>&quot;ba&quot;</code></td>
65+
</tr>
66+
</tbody>
67+
</table>
68+
69+
<p>Thus, the final <code>result</code> is <code>&quot;ba&quot;</code>.</p>
70+
</div>
71+
72+
<p><strong class="example">Example 2:</strong></p>
73+
74+
<div class="example-block">
75+
<p><strong>Input:</strong> <span class="example-io">s = &quot;z*#&quot;</span></p>
76+
77+
<p><strong>Output:</strong> <span class="example-io">&quot;&quot;</span></p>
78+
79+
<p><strong>Explanation:</strong></p>
80+
81+
<table style="border: 1px solid black;">
82+
<thead>
83+
<tr>
84+
<th style="border: 1px solid black;"><code>i</code></th>
85+
<th style="border: 1px solid black;"><code>s[i]</code></th>
86+
<th style="border: 1px solid black;">Operation</th>
87+
<th style="border: 1px solid black;">Current <code>result</code></th>
88+
</tr>
89+
</thead>
90+
<tbody>
91+
<tr>
92+
<td style="border: 1px solid black;">0</td>
93+
<td style="border: 1px solid black;"><code>&#39;z&#39;</code></td>
94+
<td style="border: 1px solid black;">Append <code>&#39;z&#39;</code></td>
95+
<td style="border: 1px solid black;"><code>&quot;z&quot;</code></td>
96+
</tr>
97+
<tr>
98+
<td style="border: 1px solid black;">1</td>
99+
<td style="border: 1px solid black;"><code>&#39;*&#39;</code></td>
100+
<td style="border: 1px solid black;">Remove the last character</td>
101+
<td style="border: 1px solid black;"><code>&quot;&quot;</code></td>
102+
</tr>
103+
<tr>
104+
<td style="border: 1px solid black;">2</td>
105+
<td style="border: 1px solid black;"><code>&#39;#&#39;</code></td>
106+
<td style="border: 1px solid black;">Duplicate the string</td>
107+
<td style="border: 1px solid black;"><code>&quot;&quot;</code></td>
108+
</tr>
109+
</tbody>
110+
</table>
111+
112+
<p>Thus, the final <code>result</code> is <code>&quot;&quot;</code>.</p>
113+
</div>
114+
115+
<p>&nbsp;</p>
116+
<p><strong>Constraints:</strong></p>
117+
118+
<ul>
119+
<li><code>1 &lt;= s.length &lt;= 20</code></li>
120+
<li><code>s</code> consists of only lowercase English letters and special characters <code>*</code>, <code>#</code>, and <code>%</code>.</li>
121+
</ul>

problems/problems_3612/problem_zh.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# 3612. 用特殊操作处理字符串 I
2+
3+
<p>给你一个字符串 <code>s</code>,它由小写英文字母和特殊字符:<code>*</code>、<code>#</code> 和 <code>%</code> 组成。</p>
4+
5+
<p>请根据以下规则从左到右处理 <code>s</code>&nbsp;中的字符,构造一个新的字符串 <code>result</code>:</p>
6+
7+
<ul>
8+
<li>如果字符是 <strong>小写</strong> 英文字母,则将其添加到 <code>result</code> 中。</li>
9+
<li>字符 <code>'*'</code> 会&nbsp;<strong>删除</strong> <code>result</code> 中的最后一个字符(如果存在)。</li>
10+
<li>字符 <code>'#'</code> 会&nbsp;<strong>复制&nbsp;</strong>当前的 <code>result</code> 并&nbsp;<strong>追加&nbsp;</strong>到其自身后面。</li>
11+
<li>字符 <code>'%'</code> 会&nbsp;<strong>反转&nbsp;</strong>当前的 <code>result</code>。</li>
12+
</ul>
13+
14+
<p>在处理完 <code>s</code> 中的所有字符后,返回最终的字符串 <code>result</code>。</p>
15+
16+
<p>&nbsp;</p>
17+
18+
<p><strong class="example">示例 1:</strong></p>
19+
20+
<div class="example-block">
21+
<p><strong>输入:</strong> <span class="example-io">s = "a#b%*"</span></p>
22+
23+
<p><strong>输出:</strong> <span class="example-io">"ba"</span></p>
24+
25+
<p><strong>解释:</strong></p>
26+
27+
<table style="border: 1px solid black;">
28+
<thead>
29+
<tr>
30+
<th style="border: 1px solid black;"><code>i</code></th>
31+
<th style="border: 1px solid black;"><code>s[i]</code></th>
32+
<th style="border: 1px solid black;">操作</th>
33+
<th style="border: 1px solid black;">当前 <code>result</code></th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
<tr>
38+
<td style="border: 1px solid black;">0</td>
39+
<td style="border: 1px solid black;"><code>'a'</code></td>
40+
<td style="border: 1px solid black;">添加 <code>'a'</code></td>
41+
<td style="border: 1px solid black;"><code>"a"</code></td>
42+
</tr>
43+
<tr>
44+
<td style="border: 1px solid black;">1</td>
45+
<td style="border: 1px solid black;"><code>'#'</code></td>
46+
<td style="border: 1px solid black;">复制 <code>result</code></td>
47+
<td style="border: 1px solid black;"><code>"aa"</code></td>
48+
</tr>
49+
<tr>
50+
<td style="border: 1px solid black;">2</td>
51+
<td style="border: 1px solid black;"><code>'b'</code></td>
52+
<td style="border: 1px solid black;">添加 <code>'b'</code></td>
53+
<td style="border: 1px solid black;"><code>"aab"</code></td>
54+
</tr>
55+
<tr>
56+
<td style="border: 1px solid black;">3</td>
57+
<td style="border: 1px solid black;"><code>'%'</code></td>
58+
<td style="border: 1px solid black;">反转 <code>result</code></td>
59+
<td style="border: 1px solid black;"><code>"baa"</code></td>
60+
</tr>
61+
<tr>
62+
<td style="border: 1px solid black;">4</td>
63+
<td style="border: 1px solid black;"><code>'*'</code></td>
64+
<td style="border: 1px solid black;">删除最后一个字符</td>
65+
<td style="border: 1px solid black;"><code>"ba"</code></td>
66+
</tr>
67+
</tbody>
68+
</table>
69+
70+
<p>因此,最终的 <code>result</code> 是 <code>"ba"</code>。</p>
71+
</div>
72+
73+
<p><strong class="example">示例 2:</strong></p>
74+
75+
<div class="example-block">
76+
<p><strong>输入:</strong> <span class="example-io">s = "z*#"</span></p>
77+
78+
<p><strong>输出:</strong> <span class="example-io">""</span></p>
79+
80+
<p><strong>解释:</strong></p>
81+
82+
<table style="border: 1px solid black;">
83+
<thead>
84+
<tr>
85+
<th style="border: 1px solid black;"><code>i</code></th>
86+
<th style="border: 1px solid black;"><code>s[i]</code></th>
87+
<th style="border: 1px solid black;">操作</th>
88+
<th style="border: 1px solid black;">当前 <code>result</code></th>
89+
</tr>
90+
</thead>
91+
<tbody>
92+
<tr>
93+
<td style="border: 1px solid black;">0</td>
94+
<td style="border: 1px solid black;"><code>'z'</code></td>
95+
<td style="border: 1px solid black;">添加 <code>'z'</code></td>
96+
<td style="border: 1px solid black;"><code>"z"</code></td>
97+
</tr>
98+
<tr>
99+
<td style="border: 1px solid black;">1</td>
100+
<td style="border: 1px solid black;"><code>'*'</code></td>
101+
<td style="border: 1px solid black;">删除最后一个字符</td>
102+
<td style="border: 1px solid black;"><code>""</code></td>
103+
</tr>
104+
<tr>
105+
<td style="border: 1px solid black;">2</td>
106+
<td style="border: 1px solid black;"><code>'#'</code></td>
107+
<td style="border: 1px solid black;">复制字符串</td>
108+
<td style="border: 1px solid black;"><code>""</code></td>
109+
</tr>
110+
</tbody>
111+
</table>
112+
113+
<p>因此,最终的 <code>result</code> 是 <code>""</code>。</p>
114+
</div>
115+
116+
<p>&nbsp;</p>
117+
118+
<p><strong>提示:</strong></p>
119+
120+
<ul>
121+
<li><code>1 &lt;= s.length &lt;= 20</code></li>
122+
<li><code>s</code> 只包含小写英文字母和特殊字符 <code>*</code>、<code>#</code> 和 <code>%</code>。</li>
123+
</ul>

0 commit comments

Comments
 (0)