Skip to content

Commit d63d318

Browse files
author
changhongyuan
committed
之前题目的md
1 parent bdf1360 commit d63d318

File tree

11 files changed

+450
-58
lines changed

11 files changed

+450
-58
lines changed

.idea/leetcode/editor.xml

Lines changed: 24 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
2+
//
3+
//
4+
//
5+
// 示例 1:
6+
//
7+
//
8+
//输入:l1 = [1,2,4], l2 = [1,3,4]
9+
//输出:[1,1,2,3,4,4]
10+
//
11+
//
12+
// 示例 2:
13+
//
14+
//
15+
//输入:l1 = [], l2 = []
16+
//输出:[]
17+
//
18+
//
19+
// 示例 3:
20+
//
21+
//
22+
//输入:l1 = [], l2 = [0]
23+
//输出:[0]
24+
//
25+
//
26+
//
27+
//
28+
// 提示:
29+
//
30+
//
31+
// 两个链表的节点数目范围是 [0, 50]
32+
// -100 <= Node.val <= 100
33+
// l1 和 l2 均按 非递减顺序 排列
34+
//
35+
// Related Topics 递归 链表 👍 2457 👎 0
36+
37+
package com.changhongyuan.leetcode.editor.cn;
38+
39+
import com.changhongyuan.leetcode.ListNode;
40+
41+
class MergeTwoSortedLists{
42+
//leetcode submit region begin(Prohibit modification and deletion)
43+
/**
44+
* Definition for singly-linked list.
45+
* public class ListNode {
46+
* int val;
47+
* ListNode next;
48+
* ListNode() {}
49+
* ListNode(int val) { this.val = val; }
50+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
51+
* }
52+
*/
53+
class Solution {
54+
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
55+
return null;
56+
}
57+
}
58+
//leetcode submit region end(Prohibit modification and deletion)
59+
60+
public static void main(String[] args) {
61+
Solution solution = new MergeTwoSortedLists().new Solution();
62+
}
63+
}

src/main/java/com/changhongyuan/leetcode/editor/cn/[7]整数反转.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public int reverse(int x) {
4545

4646
public static void main(String[] args) {
4747
Solution solution = new ReverseInteger().new Solution();
48-
int result = solution.reverse(1534236469);
48+
int result = solution.reverse(394892);
4949
System.out.println(result);
5050
}
5151
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<p>罗马数字包含以下七种字符:&nbsp;<code>I</code>,&nbsp;<code>V</code>,&nbsp;<code>X</code>,&nbsp;<code>L</code>,<code>C</code>,<code>D</code>&nbsp;&nbsp;<code>M</code>。</p>
2+
3+
<pre>
4+
<strong>字符</strong> <strong>数值</strong>
5+
I 1
6+
V 5
7+
X 10
8+
L 50
9+
C 100
10+
D 500
11+
M 1000</pre>
12+
13+
<p>例如, 罗马数字 <code>2</code> 写做&nbsp;<code>II</code>&nbsp;,即为两个并列的 1 。<code>12</code> 写做&nbsp;<code>XII</code>&nbsp;,即为&nbsp;<code>X</code>&nbsp;+&nbsp;<code>II</code>&nbsp;。 <code>27</code> 写做&nbsp;&nbsp;<code>XXVII</code>, 即为&nbsp;<code>XX</code>&nbsp;+&nbsp;<code>V</code>&nbsp;+&nbsp;<code>II</code>&nbsp;。</p>
14+
15+
<p>通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做&nbsp;<code>IIII</code>,而是&nbsp;<code>IV</code>。数字 1 在数字 5 的左边,所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地,数字 9 表示为&nbsp;<code>IX</code>。这个特殊的规则只适用于以下六种情况:</p>
16+
17+
<ul>
18+
<li><code>I</code>&nbsp;可以放在&nbsp;<code>V</code>&nbsp;(5) 和&nbsp;<code>X</code>&nbsp;(10) 的左边,来表示 4 和 9。</li>
19+
<li><code>X</code>&nbsp;可以放在&nbsp;<code>L</code>&nbsp;(50) 和&nbsp;<code>C</code>&nbsp;(100) 的左边,来表示 40 和&nbsp;90。&nbsp;</li>
20+
<li><code>C</code>&nbsp;可以放在&nbsp;<code>D</code>&nbsp;(500) 和&nbsp;<code>M</code>&nbsp;(1000) 的左边,来表示&nbsp;400 和&nbsp;900。</li>
21+
</ul>
22+
23+
<p>给定一个罗马数字,将其转换成整数。</p>
24+
25+
<p>&nbsp;</p>
26+
27+
<p><strong>示例&nbsp;1:</strong></p>
28+
29+
<pre>
30+
<strong>输入:</strong>&nbsp;s = "III"
31+
<strong>输出:</strong> 3</pre>
32+
33+
<p><strong>示例&nbsp;2:</strong></p>
34+
35+
<pre>
36+
<strong>输入:</strong>&nbsp;s = "IV"
37+
<strong>输出:</strong> 4</pre>
38+
39+
<p><strong>示例&nbsp;3:</strong></p>
40+
41+
<pre>
42+
<strong>输入:</strong>&nbsp;s = "IX"
43+
<strong>输出:</strong> 9</pre>
44+
45+
<p><strong>示例&nbsp;4:</strong></p>
46+
47+
<pre>
48+
<strong>输入:</strong>&nbsp;s = "LVIII"
49+
<strong>输出:</strong> 58
50+
<strong>解释:</strong> L = 50, V= 5, III = 3.
51+
</pre>
52+
53+
<p><strong>示例&nbsp;5:</strong></p>
54+
55+
<pre>
56+
<strong>输入:</strong>&nbsp;s = "MCMXCIV"
57+
<strong>输出:</strong> 1994
58+
<strong>解释:</strong> M = 1000, CM = 900, XC = 90, IV = 4.</pre>
59+
60+
<p>&nbsp;</p>
61+
62+
<p><strong>提示:</strong></p>
63+
64+
<ul>
65+
<li><code>1 &lt;= s.length &lt;= 15</code></li>
66+
<li><code>s</code> 仅含字符 <code>('I', 'V', 'X', 'L', 'C', 'D', 'M')</code></li>
67+
<li>题目数据保证 <code>s</code> 是一个有效的罗马数字,且表示整数在范围 <code>[1, 3999]</code> 内</li>
68+
<li>题目所给测试用例皆符合罗马数字书写规则,不会出现跨位等情况。</li>
69+
<li>IL 和 IM 这样的例子并不符合题目要求,49 应该写作 XLIX,999 应该写作 CMXCIX 。</li>
70+
<li>关于罗马数字的详尽书写规则,可以参考 <a href="https://b2b.partcommunity.com/community/knowledge/zh_CN/detail/10753/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97#knowledge_article">罗马数字 - Mathematics </a>。</li>
71+
</ul>
72+
<div><div>Related Topics</div><div><li>哈希表</li><li>数学</li><li>字符串</li></div></div><br><div><li>👍 1903</li><li>👎 0</li></div>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>编写一个函数来查找字符串数组中的最长公共前缀。</p>
2+
3+
<p>如果不存在公共前缀,返回空字符串&nbsp;<code>""</code>。</p>
4+
5+
<p>&nbsp;</p>
6+
7+
<p><strong>示例 1:</strong></p>
8+
9+
<pre>
10+
<strong>输入:</strong>strs = ["flower","flow","flight"]
11+
<strong>输出:</strong>"fl"
12+
</pre>
13+
14+
<p><strong>示例 2:</strong></p>
15+
16+
<pre>
17+
<strong>输入:</strong>strs = ["dog","racecar","car"]
18+
<strong>输出:</strong>""
19+
<strong>解释:</strong>输入不存在公共前缀。</pre>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong>提示:</strong></p>
24+
25+
<ul>
26+
<li><code>1 &lt;= strs.length &lt;= 200</code></li>
27+
<li><code>0 &lt;= strs[i].length &lt;= 200</code></li>
28+
<li><code>strs[i]</code> 仅由小写英文字母组成</li>
29+
</ul>
30+
<div><div>Related Topics</div><div><li>字符串</li></div></div><br><div><li>👍 2280</li><li>👎 0</li></div>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<p>给定一个整数数组 <code>nums</code>&nbsp;和一个整数目标值 <code>target</code>,请你在该数组中找出 <strong>和为目标值 </strong><em><code>target</code></em>&nbsp; 的那&nbsp;<strong>两个</strong>&nbsp;整数,并返回它们的数组下标。</p>
2+
3+
<p>你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。</p>
4+
5+
<p>你可以按任意顺序返回答案。</p>
6+
7+
<p>&nbsp;</p>
8+
9+
<p><strong>示例 1:</strong></p>
10+
11+
<pre>
12+
<strong>输入:</strong>nums = [2,7,11,15], target = 9
13+
<strong>输出:</strong>[0,1]
14+
<strong>解释:</strong>因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。
15+
</pre>
16+
17+
<p><strong>示例 2:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong>nums = [3,2,4], target = 6
21+
<strong>输出:</strong>[1,2]
22+
</pre>
23+
24+
<p><strong>示例 3:</strong></p>
25+
26+
<pre>
27+
<strong>输入:</strong>nums = [3,3], target = 6
28+
<strong>输出:</strong>[0,1]
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
37+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
38+
<li><code>-10<sup>9</sup> &lt;= target &lt;= 10<sup>9</sup></code></li>
39+
<li><strong>只会存在一个有效答案</strong></li>
40+
</ul>
41+
42+
<p><strong>进阶:</strong>你可以想出一个时间复杂度小于 <code>O(n<sup>2</sup>)</code> 的算法吗?</p>
43+
<div><div>Related Topics</div><div><li>数组</li><li>哈希表</li></div></div><br><div><li>👍 14520</li><li>👎 0</li></div>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<p>给定一个只包括 <code>'('</code>,<code>')'</code>,<code>'{'</code>,<code>'}'</code>,<code>'['</code>,<code>']'</code> 的字符串 <code>s</code> ,判断字符串是否有效。</p>
2+
3+
<p>有效字符串需满足:</p>
4+
5+
<ol>
6+
<li>左括号必须用相同类型的右括号闭合。</li>
7+
<li>左括号必须以正确的顺序闭合。</li>
8+
</ol>
9+
10+
<p> </p>
11+
12+
<p><strong>示例 1:</strong></p>
13+
14+
<pre>
15+
<strong>输入:</strong>s = "()"
16+
<strong>输出:</strong>true
17+
</pre>
18+
19+
<p><strong>示例 2:</strong></p>
20+
21+
<pre>
22+
<strong>输入:</strong>s = "()[]{}"
23+
<strong>输出:</strong>true
24+
</pre>
25+
26+
<p><strong>示例 3:</strong></p>
27+
28+
<pre>
29+
<strong>输入:</strong>s = "(]"
30+
<strong>输出:</strong>false
31+
</pre>
32+
33+
<p><strong>示例 4:</strong></p>
34+
35+
<pre>
36+
<strong>输入:</strong>s = "([)]"
37+
<strong>输出:</strong>false
38+
</pre>
39+
40+
<p><strong>示例 5:</strong></p>
41+
42+
<pre>
43+
<strong>输入:</strong>s = "{[]}"
44+
<strong>输出:</strong>true</pre>
45+
46+
<p> </p>
47+
48+
<p><strong>提示:</strong></p>
49+
50+
<ul>
51+
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
52+
<li><code>s</code> 仅由括号 <code>'()[]{}'</code> 组成</li>
53+
</ul>
54+
<div><div>Related Topics</div><div><li>栈</li><li>字符串</li></div></div><br><div><li>👍 3303</li><li>👎 0</li></div>

0 commit comments

Comments
 (0)