Skip to content

Commit 00fa9f5

Browse files
committed
update
1 parent 48daf27 commit 00fa9f5

13 files changed

+818
-35
lines changed

.idea/leetcode-pro/editor.xml

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
## leetcode-editor config
55
CodeFileName:
66
```java
7-
$!velocityTool.camelCaseName(${question.titleSlug})
7+
Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})
88
```
99
CodeTemplate:
1010
```java
11+
package com.shuzijun.leetcode.editor.cn;
1112
${question.content}
1213

13-
package com.shuzijun.leetcode.editor.en;
14-
public class $!velocityTool.camelCaseName(${question.titleSlug}){
15-
public static void main(String[] args) {
16-
Solution solution = new $!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
14+
public class Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug}){
15+
public static void main(String[] args) {
16+
Solution solution = new Q${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
1717
}
1818
${question.code}
1919
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.shuzijun.leetcode.editor.cn;
2+
/**
3+
<p>给定两个整数,被除数&nbsp;<code>dividend</code>&nbsp;和除数&nbsp;<code>divisor</code>。将两数相除,要求不使用乘法、除法和 mod 运算符。</p>
4+
5+
<p>返回被除数&nbsp;<code>dividend</code>&nbsp;除以除数&nbsp;<code>divisor</code>&nbsp;得到的商。</p>
6+
7+
<p>整数除法的结果应当截去(<code>truncate</code>)其小数部分,例如:<code>truncate(8.345) = 8</code> 以及 <code>truncate(-2.7335) = -2</code></p>
8+
9+
<p>&nbsp;</p>
10+
11+
<p><strong>示例&nbsp;1:</strong></p>
12+
13+
<pre><strong>输入:</strong> dividend = 10, divisor = 3
14+
<strong>输出:</strong> 3
15+
<strong>解释: </strong>10/3 = truncate(3.33333..) = truncate(3) = 3</pre>
16+
17+
<p><strong>示例&nbsp;2:</strong></p>
18+
19+
<pre><strong>输入:</strong> dividend = 7, divisor = -3
20+
<strong>输出:</strong> -2
21+
<strong>解释:</strong> 7/-3 = truncate(-2.33333..) = -2</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p><strong>提示:</strong></p>
26+
27+
<ul>
28+
<li>被除数和除数均为 32 位有符号整数。</li>
29+
<li>除数不为&nbsp;0。</li>
30+
<li>假设我们的环境只能存储 32 位有符号整数,其数值范围是 [&minus;2<sup>31</sup>,&nbsp; 2<sup>31&nbsp;</sup>&minus; 1]。本题中,如果除法结果溢出,则返回 2<sup>31&nbsp;</sup>&minus; 1。</li>
31+
</ul>
32+
<div><div>Related Topics</div><div><li>位运算</li><li>数学</li></div></div><br><div><li>👍 625</li><li>👎 0</li></div>
33+
*/
34+
35+
public class Q29DivideTwoIntegers{
36+
public static void main(String[] args) {
37+
Solution solution = new Q29DivideTwoIntegers().new Solution();
38+
}
39+
//leetcode submit region begin(Prohibit modification and deletion)
40+
class Solution {
41+
public int divide(int dividend, int divisor) {
42+
return 0;
43+
}
44+
}
45+
//leetcode submit region end(Prohibit modification and deletion)
46+
47+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.shuzijun.leetcode.editor.cn;
2+
3+
import java.util.List;
4+
5+
/**
6+
<p>给定一个字符串 <code>s</code><strong> </strong>和一些 <strong>长度相同</strong> 的单词 <code>words</code><strong> 。</strong>找出 <code>s</code><strong> </strong>中恰好可以由 <code>words</code><strong> </strong>中所有单词串联形成的子串的起始位置。</p>
7+
8+
<p>注意子串要与 <code>words</code><strong> </strong>中的单词完全匹配,<strong>中间不能有其他字符 </strong>,但不需要考虑 <code>words</code><strong> </strong>中单词串联的顺序。</p>
9+
10+
<p> </p>
11+
12+
<p><strong>示例 1:</strong></p>
13+
14+
<pre>
15+
<strong>输入:</strong>s = "barfoothefoobarman", words = ["foo","bar"]
16+
<strong>输出:</strong><code>[0,9]</code>
17+
<strong>解释:</strong>
18+
从索引 0 和 9 开始的子串分别是 "barfoo" 和 "foobar" 。
19+
输出的顺序不重要, [9,0] 也是有效答案。
20+
</pre>
21+
22+
<p><strong>示例 2:</strong></p>
23+
24+
<pre>
25+
<strong>输入:</strong>s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
26+
<code><strong>输出:</strong>[]</code>
27+
</pre>
28+
29+
<p><strong>示例 3:</strong></p>
30+
31+
<pre>
32+
<strong>输入:</strong>s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
33+
<strong>输出:</strong>[6,9,12]
34+
</pre>
35+
36+
<p> </p>
37+
38+
<p><strong>提示:</strong></p>
39+
40+
<ul>
41+
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
42+
<li><code>s</code> 由小写英文字母组成</li>
43+
<li><code>1 <= words.length <= 5000</code></li>
44+
<li><code>1 <= words[i].length <= 30</code></li>
45+
<li><code>words[i]</code> 由小写英文字母组成</li>
46+
</ul>
47+
<div><div>Related Topics</div><div><li>哈希表</li><li>字符串</li><li>滑动窗口</li></div></div><br><div><li>👍 510</li><li>👎 0</li></div>
48+
*/
49+
50+
public class Q30SubstringWithConcatenationOfAllWords{
51+
public static void main(String[] args) {
52+
Solution solution = new Q30SubstringWithConcatenationOfAllWords().new Solution();
53+
}
54+
//leetcode submit region begin(Prohibit modification and deletion)
55+
class Solution {
56+
public List<Integer> findSubstring(String s, String[] words) {
57+
return null;
58+
}
59+
}
60+
//leetcode submit region end(Prohibit modification and deletion)
61+
62+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.shuzijun.leetcode.editor.cn;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* <p>实现获取 <strong>下一个排列</strong> 的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列。</p>
7+
*
8+
* <p>如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列)。</p>
9+
*
10+
* <p>必须<strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank"> 原地 </a></strong>修改,只允许使用额外常数空间。</p>
11+
*
12+
* <p> </p>
13+
*
14+
* <p><strong>示例 1:</strong></p>
15+
*
16+
* <pre>
17+
* <strong>输入:</strong>nums = [1,2,3]
18+
* <strong>输出:</strong>[1,3,2]
19+
* </pre>
20+
*
21+
* <p><strong>示例 2:</strong></p>
22+
*
23+
* <pre>
24+
* <strong>输入:</strong>nums = [3,2,1]
25+
* <strong>输出:</strong>[1,2,3]
26+
* </pre>
27+
*
28+
* <p><strong>示例 3:</strong></p>
29+
*
30+
* <pre>
31+
* <strong>输入:</strong>nums = [1,1,5]
32+
* <strong>输出:</strong>[1,5,1]
33+
* </pre>
34+
*
35+
* <p><strong>示例 4:</strong></p>
36+
*
37+
* <pre>
38+
* <strong>输入:</strong>nums = [1]
39+
* <strong>输出:</strong>[1]
40+
* </pre>
41+
*
42+
* <p> </p>
43+
*
44+
* <p><strong>提示:</strong></p>
45+
*
46+
* <ul>
47+
* <li><code>1 <= nums.length <= 100</code></li>
48+
* <li><code>0 <= nums[i] <= 100</code></li>
49+
* </ul>
50+
* <div><div>Related Topics</div><div><li>数组</li><li>双指针</li></div></div><br><div><li>👍 1247</li><li>👎 0</li></div>
51+
*/
52+
53+
public class Q31NextPermutation {
54+
public static void main(String[] args) {
55+
Solution solution = new Q31NextPermutation().new Solution();
56+
int[] nums = new int[]{2,3,1};
57+
solution.nextPermutation(nums);
58+
System.out.println(Arrays.toString(nums));
59+
}
60+
61+
// [4,5,2,6,3,1]
62+
//leetcode submit region begin(Prohibit modification and deletion)
63+
class Solution {
64+
public void nextPermutation(int[] nums) {
65+
int i = nums.length - 2;
66+
while (i >= 0 && nums[i] >= nums[i + 1]) {
67+
i--;
68+
}
69+
if (i >= 0) {
70+
int j = nums.length - 1;
71+
while (j >= 0 && nums[i] >= nums[j]) {
72+
j--;
73+
}
74+
swap(nums, i, j);
75+
}
76+
reverse(nums, i + 1);
77+
}
78+
79+
public void swap(int[] nums, int i, int j) {
80+
int temp = nums[i];
81+
nums[i] = nums[j];
82+
nums[j] = temp;
83+
}
84+
85+
public void reverse(int[] nums, int start) {
86+
int left = start, right = nums.length - 1;
87+
while (left < right) {
88+
swap(nums, left, right);
89+
left++;
90+
right--;
91+
}
92+
}
93+
94+
}
95+
//leetcode submit region end(Prohibit modification and deletion)
96+
97+
}

0 commit comments

Comments
 (0)