Skip to content

Commit a6b786d

Browse files
committed
把1个tab换成4个空格
1 parent 3378e93 commit a6b786d

File tree

202 files changed

+4969
-4987
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+4969
-4987
lines changed

java/001. Two Sum.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +0,0 @@
1-
public class Solution {
2-
public int[] twoSum(int[] numbers, int target) {
3-
int[] res = new int[2];
4-
Map map = new HashMap();
5-
for (int i = 0; i < numbers.length; i++) {
6-
map.put(numbers[i], i);
7-
}
8-
for (int i = 0; i < numbers.length; i++) {
9-
int gap = target - numbers[i];
10-
if (map.get(gap) != null && (int) map.get(gap) != i) {
11-
res[0] = i + 1;
12-
res[1] = (int) map.get(gap) + 1;
13-
break;
14-
}
15-
}
16-
return res;
17-
}
18-
}

java/002. Add Two Numbers.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
*/
99
public class Solution {
1010
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
11-
return add(l1,l2,true);
11+
return add(l1,l2,true);
1212
}
1313
public ListNode add(ListNode l1, ListNode l2,boolean flag) {
14-
boolean a=l1==null;
15-
boolean b=l2==null;
16-
if (a&&b&&flag) {
17-
return null;
18-
}
19-
int val=(a?0:l1.val)+(b?0:l2.val)+(flag?0:1);
20-
int v=val%10;
21-
boolean f=(v==val);
22-
ListNode answer=new ListNode(v);
23-
answer.next=add(a?null:l1.next,b?null:l2.next,f);
24-
return answer;
14+
boolean a=l1==null;
15+
boolean b=l2==null;
16+
if (a&&b&&flag) {
17+
return null;
18+
}
19+
int val=(a?0:l1.val)+(b?0:l2.val)+(flag?0:1);
20+
int v=val%10;
21+
boolean f=(v==val);
22+
ListNode answer=new ListNode(v);
23+
answer.next=add(a?null:l1.next,b?null:l2.next,f);
24+
return answer;
2525
}
2626
}

java/003. Longest Substring Without Repeating Characters.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ public int lengthOfLongestSubstring(String s) {
44
Map<String,Integer> map=new HashMap<String, Integer>();
55
List<String> list=new LinkedList<String>();
66
for (int i = 0; i < s.length(); i++) {
7-
String k=s.substring(i, i+1);
8-
if (map.get(k) != null) {
9-
int n=map.get(k)-map.get(list.get(0))+1;
10-
for (int j = 0; j < n; j++) {
11-
map.remove(list.get(0));
12-
list.remove(0);
13-
}
14-
}
15-
map.put(k, i);
16-
list.add(k);
17-
if (list.size()>answer) {
18-
answer=list.size();
19-
}
20-
}
21-
return answer;
7+
String k=s.substring(i, i+1);
8+
if (map.get(k) != null) {
9+
int n=map.get(k)-map.get(list.get(0))+1;
10+
for (int j = 0; j < n; j++) {
11+
map.remove(list.get(0));
12+
list.remove(0);
13+
}
14+
}
15+
map.put(k, i);
16+
list.add(k);
17+
if (list.size()>answer) {
18+
answer=list.size();
19+
}
20+
}
21+
return answer;
2222
}
2323
}

java/006. ZigZag Conversion.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ public String convert(String s, int numRows) {
55
}else{
66
int k=numRows*2-2;
77
String[] res=new String[numRows];
8-
for (int i = 0; i < res.length; i++) {
9-
res[i]="";
10-
}
11-
int step=0;
12-
int j=0;
13-
for (int i = 0; i < s.length(); i++) {
14-
step++;
15-
if (step<=numRows) {
16-
j=step;
17-
}else {
18-
j=numRows-(step-numRows);
19-
}
20-
res[j-1]+=s.substring(i, i+1);
21-
if (step==k) {
22-
step=0;
23-
}
24-
}
25-
String result="";
26-
for (int i = 0; i < res.length; i++) {
27-
result+=res[i];
28-
}
29-
return result;
8+
for (int i = 0; i < res.length; i++) {
9+
res[i]="";
10+
}
11+
int step=0;
12+
int j=0;
13+
for (int i = 0; i < s.length(); i++) {
14+
step++;
15+
if (step<=numRows) {
16+
j=step;
17+
}else {
18+
j=numRows-(step-numRows);
19+
}
20+
res[j-1]+=s.substring(i, i+1);
21+
if (step==k) {
22+
step=0;
23+
}
24+
}
25+
String result="";
26+
for (int i = 0; i < res.length; i++) {
27+
result+=res[i];
28+
}
29+
return result;
3030
}
3131
}
3232
}

java/007. Reverse Integer.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
public class Solution {
22
public int reverse(int x) {
33
String str=String.valueOf(x);
4-
String r="";
5-
int re=0;
6-
if (x<0) {
7-
for (int i = str.length()-1; i >0 ; i--) {
8-
r+=str.substring(i,i+1);
9-
}
10-
r="-"+r;
11-
}else {
12-
for (int i = str.length()-1; i >-1 ; i--) {
13-
r+=str.substring(i,i+1);
14-
}
15-
}
16-
try {
17-
re=Integer.parseInt(r);
18-
19-
} catch (Exception e) {
20-
21-
}
22-
return re;
4+
String r="";
5+
int re=0;
6+
if (x<0) {
7+
for (int i = str.length()-1; i >0 ; i--) {
8+
r+=str.substring(i,i+1);
9+
}
10+
r="-"+r;
11+
}else {
12+
for (int i = str.length()-1; i >-1 ; i--) {
13+
r+=str.substring(i,i+1);
14+
}
15+
}
16+
try {
17+
re=Integer.parseInt(r);
18+
19+
} catch (Exception e) {
20+
21+
}
22+
return re;
2323
}
2424
}

java/009. Palindrome Number.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
public class Solution {
22
public boolean isPalindrome(int x) {
3-
if (x < 0) {
4-
return false;
5-
}
6-
int n = x;
7-
int a = 0;
8-
int p = 1;
9-
while (x != 0) {
10-
x /= 10;
11-
a++;
12-
p *= 10;
13-
if (a==1) {
14-
p/=10;
15-
}
16-
}
17-
int b = a / 2;
18-
if (b == 0) {
19-
return true;
20-
}
3+
if (x < 0) {
4+
return false;
5+
}
6+
int n = x;
7+
int a = 0;
8+
int p = 1;
9+
while (x != 0) {
10+
x /= 10;
11+
a++;
12+
p *= 10;
13+
if (a==1) {
14+
p/=10;
15+
}
16+
}
17+
int b = a / 2;
18+
if (b == 0) {
19+
return true;
20+
}
2121

22-
for (int i = 0; i < b; i++) {
23-
int begin = n / p;
24-
int end = n % 10;
25-
if (begin != end) {
26-
return false;
27-
} else {
28-
n = n - (begin * p);
29-
p /= 100;
30-
n = (n - end) / 10;
31-
}
32-
}
33-
return true;
34-
}
22+
for (int i = 0; i < b; i++) {
23+
int begin = n / p;
24+
int end = n % 10;
25+
if (begin != end) {
26+
return false;
27+
} else {
28+
n = n - (begin * p);
29+
p /= 100;
30+
n = (n - end) / 10;
31+
}
32+
}
33+
return true;
34+
}
3535
}
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
public class Solution {
22
public boolean isMatch(String s, String p) {
33
if (p.length()==0) {
4-
return s.length()==0;
5-
}
4+
return s.length()==0;
5+
}
66
if (s.length()==0) {
7-
if (p.length()%2!=0) {
8-
return false;
9-
}
10-
char[] c=p.toCharArray();
11-
for (int i = 1; i < c.length; i+=2) {
12-
if (c[i]!=&#39;*&#39;) {
13-
return false;
14-
}
15-
}
16-
return true;
17-
}
7+
if (p.length()%2!=0) {
8+
return false;
9+
}
10+
char[] c=p.toCharArray();
11+
for (int i = 1; i < c.length; i+=2) {
12+
if (c[i]!=&#39;*&#39;) {
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
1818
int pl=p.length();
1919
int sl=s.length();
2020
String ep=p.substring(pl-1,pl);
2121
if (ep.equals("*")) {
22-
if (p.substring(pl-2,pl-1).equals(".")) {
23-
for (int i = sl-1; i >=0-1; i--) {
24-
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
25-
return true;
26-
}
27-
}
28-
return false;
29-
}else {
30-
String k=p.substring(pl-2,pl-1);
31-
for (int i = sl-1; i >=0; i--) {
32-
String t=s.substring(i,i+1);
33-
if (t.equals(k)) {
34-
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
35-
return true;
36-
}
37-
}else {
38-
return isMatch(s.substring(0, i+1),p.substring(0, pl-2));
39-
}
40-
}
41-
return isMatch("",p.substring(0, pl-2));
42-
}
43-
}else if(ep.equals(".")){
44-
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
45-
}else {
46-
String es=s.substring(sl-1,sl);
47-
if (ep.equals(es)) {
48-
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
49-
}
50-
return false;
51-
}
22+
if (p.substring(pl-2,pl-1).equals(".")) {
23+
for (int i = sl-1; i >=0-1; i--) {
24+
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
25+
return true;
26+
}
27+
}
28+
return false;
29+
}else {
30+
String k=p.substring(pl-2,pl-1);
31+
for (int i = sl-1; i >=0; i--) {
32+
String t=s.substring(i,i+1);
33+
if (t.equals(k)) {
34+
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
35+
return true;
36+
}
37+
}else {
38+
return isMatch(s.substring(0, i+1),p.substring(0, pl-2));
39+
}
40+
}
41+
return isMatch("",p.substring(0, pl-2));
42+
}
43+
}else if(ep.equals(".")){
44+
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
45+
}else {
46+
String es=s.substring(sl-1,sl);
47+
if (ep.equals(es)) {
48+
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
49+
}
50+
return false;
51+
}
5252
}
5353
}

java/011. Container With Most Water.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ public int maxArea(int[] height) {
44
int right=height.length-1;
55
int ans=(right-left)*Math.min(height[left], height[right]);
66
while (right>left) {
7-
int water=(right-left)*Math.min(height[left], height[right]);
8-
if (water>ans) {
9-
ans=water;
10-
}
11-
if (height[left]<height[right]) {
12-
left++;
13-
}else {
14-
right--;
15-
}
16-
}
7+
int water=(right-left)*Math.min(height[left], height[right]);
8+
if (water>ans) {
9+
ans=water;
10+
}
11+
if (height[left]<height[right]) {
12+
left++;
13+
}else {
14+
right--;
15+
}
16+
}
1717
return ans;
1818
}
1919
}

0 commit comments

Comments
 (0)