Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 862485e

Browse filesBrowse files
author
Administrator
committed
Initial commit
0 parents  commit 862485e
Copy full SHA for 862485e

File tree

Expand file treeCollapse file tree

305 files changed

+8594
-0
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

305 files changed

+8594
-0
lines changed

‎.idea/.name

Copy file name to clipboardExpand all lines: .idea/.name
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/compiler.xml

Copy file name to clipboardExpand all lines: .idea/compiler.xml
+22Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/copyright/profiles_settings.xml

Copy file name to clipboardExpand all lines: .idea/copyright/profiles_settings.xml
+3Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/misc.xml

Copy file name to clipboardExpand all lines: .idea/misc.xml
+19Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml

Copy file name to clipboardExpand all lines: .idea/modules.xml
+87Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/uiDesigner.xml

Copy file name to clipboardExpand all lines: .idea/uiDesigner.xml
+124Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/vcs.xml

Copy file name to clipboardExpand all lines: .idea/vcs.xml
+6Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
847 Bytes
Binary file not shown.
Binary file not shown.
979 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
666 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
732 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎【001】【TwoSum】/src/Main.java

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Author: Íõ¿¡³¬
3+
* Date: 2015-06-18
4+
* Time: 09:17
5+
* Declaration: All Rights Reserved !!!
6+
*/
7+
public class Main {
8+
public static void main(String[] args) {
9+
int[] result = new Solution().twoSum(new int[]{0, 4, 3, 0}, 0);
10+
11+
System.out.println("[" + result[0] + " ," + result[1] + "]");
12+
}
13+
}
+92Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import java.util.Arrays;
2+
3+
/**
4+
* Author: 王俊超
5+
* Date: 2015-06-17
6+
* Time: 20:27
7+
* Declaration: All Rights Reserved !!!
8+
*/
9+
public class Solution {
10+
private static class Node implements Comparable<Node> {
11+
int val;
12+
int idx;
13+
14+
public Node() {
15+
}
16+
17+
public Node(int val, int idx) {
18+
this.val = val;
19+
this.idx = idx;
20+
}
21+
22+
@Override
23+
public int compareTo(Node o) {
24+
if (o == null) {
25+
return -1;
26+
}
27+
return this.val - o.val;
28+
}
29+
}
30+
31+
32+
/**
33+
* <pre>
34+
* Given an array of integers, find two numbers such that they add up to a specific target number.
35+
* The function twoSum should return indices of the two numbers such that they add up to the target,
36+
* where index1 must be less than index2. Please note that your returned answers (both index1 and index2)
37+
* are not zero-based.
38+
* You may assume that each input would have exactly one solution.
39+
*
40+
* Input: numbers={2, 7, 11, 15}, target=9
41+
* Output: index1=1, index2=2
42+
*
43+
* 题目大意
44+
* 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。
45+
* 要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。
46+
* 请注意一点,你返回的结果(包括index1和index2)都不是基于0开始的。你可以假设每一个输入肯定只有一个结果。
47+
*
48+
* 解题思路
49+
* 创建一个辅助类数组,对辅助类进行排序,使用两个指针,开始时分别指向数组的两端,看这两个下标对应的值是否
50+
* 等于目标值,如果等于就从辅助类中找出记录的下标,构造好返回结果,返回。如果大于就让右边的下标向左移,
51+
* 进入下一次匹配,如果小于就让左边的下标向右移动,进入下一次匹配,直到所有的数据都处理完
52+
* </pre>
53+
*
54+
* @param nums
55+
* @param target
56+
* @return
57+
*/
58+
59+
public int[] twoSum(int[] nums, int target) {
60+
int[] result = {0, 0};
61+
62+
Node[] tmp = new Node[nums.length];
63+
for (int i = 0; i < nums.length; i++) {
64+
tmp[i] = new Node(nums[i], i);
65+
}
66+
67+
Arrays.sort(tmp);
68+
69+
int lo = 0;
70+
int hi = nums.length - 1;
71+
72+
73+
while (lo < hi) {
74+
if (tmp[lo].val + tmp[hi].val == target) {
75+
76+
if (tmp[lo].idx > tmp[hi].idx) {
77+
result[0] = tmp[hi].idx + 1;
78+
result[1] = tmp[lo].idx + 1;
79+
} else {
80+
result[0] = tmp[lo].idx + 1;
81+
result[1] = tmp[hi].idx + 1;
82+
}
83+
break;
84+
} else if (tmp[lo].val + tmp[hi].val > target) {
85+
hi--;
86+
} else {
87+
lo++;
88+
}
89+
}
90+
return result;
91+
}
92+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Author: Íõ¿¡³¬
3+
* Date: 2015-08-21
4+
* Time: 16:05
5+
* Declaration: All Rights Reserved !!!
6+
*/
7+
public class ListNode {
8+
int val;
9+
ListNode next;
10+
11+
ListNode(int val) {
12+
this.val = val;
13+
}
14+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.