Skip to content

Commit 1c09fa0

Browse files
author
changhongyuan
committed
第一题,第二题
1 parent f23d878 commit 1c09fa0

27 files changed

+287
-16
lines changed

.idea/.gitignore

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

.idea/compiler.xml

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

.idea/jarRepositories.xml

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

.idea/leetcode/editor.xml

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

.idea/misc.xml

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

.idea/modules.xml

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

.idea/vcs.xml

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

leetcode-question.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<excludeFolder url="file://$MODULE_DIR$/target" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
</component>
13+
</module>

src/main/java/com/shuzijun/leetcode/HelloWorld.java renamed to src/main/java/com/changhongyuan/leetcode/HelloWorld.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.shuzijun.leetcode;
1+
package com.changhongyuan.leetcode;
22

33
/**
44
* Created with IntelliJ IDEA.

src/main/java/com/shuzijun/leetcode/ListNode.java renamed to src/main/java/com/changhongyuan/leetcode/ListNode.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.shuzijun.leetcode;
1+
package com.changhongyuan.leetcode;
22

33
/**
44
@@ -11,6 +11,11 @@ public ListNode(int x) {
1111
val = x;
1212
}
1313

14+
public ListNode(int x, ListNode next) {
15+
val = x;
16+
this.next = next;
17+
}
18+
1419
@Override
1520
public String toString() {
1621
final StringBuilder sb = new StringBuilder().append(val);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.changhongyuan.leetcode.editor.cn;//给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
2+
//
3+
// 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。
4+
//
5+
//
6+
//
7+
// 示例:
8+
//
9+
// 给定 nums = [2, 7, 11, 15], target = 9
10+
//
11+
//因为 nums[0] + nums[1] = 2 + 7 = 9
12+
//所以返回 [0, 1]
13+
//
14+
// Related Topics 数组 哈希表
15+
// 👍 9822 👎 0
16+
17+
18+
//leetcode submit region begin(Prohibit modification and deletion)
19+
class Solution {
20+
public int[] twoSum(int[] nums, int target) {
21+
for (int i = 0; i < nums.length; i++) {
22+
for (int j = i + 1; j < nums.length; j++) {
23+
if (nums[i] + nums[j] == target) return new int[]{i, j};
24+
}
25+
}
26+
return null;
27+
}
28+
}
29+
//leetcode submit region end(Prohibit modification and deletion)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。
2+
//
3+
// 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。
4+
//
5+
// 您可以假设除了数字 0 之外,这两个数都不会以 0 开头。
6+
//
7+
// 示例:
8+
//
9+
// 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)
10+
//输出:7 -> 0 -> 8
11+
//原因:342 + 465 = 807
12+
//
13+
// Related Topics 链表 数学
14+
// 👍 5378 👎 0
15+
16+
package com.changhongyuan.leetcode.editor.cn;
17+
18+
import com.changhongyuan.leetcode.ListNode;
19+
20+
class AddTwoNumbers{
21+
//leetcode submit region begin(Prohibit modification and deletion)
22+
/**
23+
* Definition for singly-linked list.
24+
* public class ListNode {
25+
* int val;
26+
* ListNode next;
27+
* ListNode() {}
28+
* ListNode(int val) { this.val = val; }
29+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
30+
* }
31+
*/
32+
class Solution {
33+
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
34+
// ListNode result = new ListNode(0);
35+
return doCal(l1, l2, 0);
36+
}
37+
38+
public ListNode doCal(ListNode l1, ListNode l2, int in) {
39+
if (null == l1 && null == l2 && in == 0) {
40+
return null;
41+
}
42+
int n1 = null != l1 ? l1.val : 0;
43+
int n2 = null != l2 ? l2.val : 0;
44+
int sum = n1 + n2 + in;
45+
ListNode result = new ListNode(sum % 10);
46+
result.next = doCal(null != l1 ? l1.next : null, null != l2 ? l2.next : null, sum / 10);
47+
return result;
48+
}
49+
}
50+
//leetcode submit region end(Prohibit modification and deletion)
51+
52+
public static void main(String[] args) {
53+
Solution solution = new AddTwoNumbers().new Solution();
54+
// ListNode l1 = new ListNode(9);
55+
// l1.next = new ListNode(9);
56+
// l1.next.next = new ListNode(9);
57+
// ListNode l2 = new ListNode(5);
58+
// l2.next = new ListNode(6);
59+
// l2.next.next = new ListNode(4);
60+
// ListNode result = solution.addTwoNumbers(l1, l2);
61+
// System.out.println(result);
62+
ListNode l1 = new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9)))))));
63+
ListNode l2 = new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9))));
64+
System.out.println("l1 is " + l1);
65+
System.out.println("l2 is " + l2);
66+
ListNode result = solution.addTwoNumbers(l1, l2);
67+
System.out.println(result);
68+
69+
}
70+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
2+
//
3+
// 示例 1:
4+
//
5+
// 输入: 123
6+
//输出: 321
7+
//
8+
//
9+
// 示例 2:
10+
//
11+
// 输入: -123
12+
//输出: -321
13+
//
14+
//
15+
// 示例 3:
16+
//
17+
// 输入: 120
18+
//输出: 21
19+
//
20+
//
21+
// 注意:
22+
//
23+
// 假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231, 231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。
24+
// Related Topics 数学
25+
// 👍 2396 👎 0
26+
27+
package com.changhongyuan.leetcode.editor.cn;
28+
class ReverseInteger{
29+
//leetcode submit region begin(Prohibit modification and deletion)
30+
class Solution {
31+
public int reverse(int x) {
32+
int result = 0;
33+
return result;
34+
}
35+
}
36+
//leetcode submit region end(Prohibit modification and deletion)
37+
38+
public static void main(String[] args) {
39+
Solution solution = new ReverseInteger().new Solution();
40+
System.out.println();
41+
}
42+
}

src/main/java/com/changhongyuan/leetcode/editor/cn/all.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/changhongyuan/leetcode/editor/cn/translation.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/shuzijun/leetcode/editor/en/AddTwoNumbers.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/AddTwoNumbers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//
1212
//
1313

14-
package com.shuzijun.leetcode.editor.en;
14+
package com.changhongyuan.leetcode.editor.en;
1515

16-
import com.shuzijun.leetcode.ListNode;
16+
import com.changhongyuan.leetcode.ListNode;
1717

1818
public class AddTwoNumbers {
1919
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/ContainerWithMostWater.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/ContainerWithMostWater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//Output: 49
1818
//
1919

20-
package com.shuzijun.leetcode.editor.en;
20+
package com.changhongyuan.leetcode.editor.en;
2121

2222
public class ContainerWithMostWater {
2323
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/GenerateParentheses.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/GenerateParentheses.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//]
1616
//
1717

18-
package com.shuzijun.leetcode.editor.en;
18+
package com.changhongyuan.leetcode.editor.en;
1919

2020
import java.util.ArrayList;
2121
import java.util.List;

src/main/java/com/shuzijun/leetcode/editor/en/PalindromeNumber.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/PalindromeNumber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// Coud you solve it without converting the integer to a string?
2929
//
3030

31-
package com.shuzijun.leetcode.editor.en;
31+
package com.changhongyuan.leetcode.editor.en;
3232

3333
public class PalindromeNumber {
3434
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/ReverseInteger.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/ReverseInteger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
2626
//
2727

28-
package com.shuzijun.leetcode.editor.en;
28+
package com.changhongyuan.leetcode.editor.en;
2929

3030
public class ReverseInteger {
3131
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/SearchInRotatedSortedArray.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/SearchInRotatedSortedArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//Output: -1
2323
//
2424

25-
package com.shuzijun.leetcode.editor.en;
25+
package com.changhongyuan.leetcode.editor.en;
2626

2727
public class SearchInRotatedSortedArray {
2828
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/StringToIntegerAtoi.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/StringToIntegerAtoi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
//  Thefore INT_MIN (−231) is returned.
5757
//
5858

59-
package com.shuzijun.leetcode.editor.en;
59+
package com.changhongyuan.leetcode.editor.en;
6060

6161
public class StringToIntegerAtoi {
6262
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/SwapNodesInPairs.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/SwapNodesInPairs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//
1212
//
1313

14-
package com.shuzijun.leetcode.editor.en;
14+
package com.changhongyuan.leetcode.editor.en;
1515

16-
import com.shuzijun.leetcode.ListNode;
16+
import com.changhongyuan.leetcode.ListNode;
1717

1818
public class SwapNodesInPairs {
1919
public static void main(String[] args) {

src/main/java/com/shuzijun/leetcode/editor/en/ThreeSum.java renamed to src/main/java/com/changhongyuan/leetcode/editor/en/ThreeSum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//
1818
//
1919

20-
package com.shuzijun.leetcode.editor.en;
20+
package com.changhongyuan.leetcode.editor.en;
2121

2222
import java.util.ArrayList;
2323
import java.util.Arrays;

0 commit comments

Comments
 (0)