Skip to content

Commit

Permalink
把1个tab换成4个空格
Browse files Browse the repository at this point in the history
  • Loading branch information
SmokerX committed Apr 26, 2016
1 parent 3378e93 commit a6b786d
Show file tree
Hide file tree
Showing 202 changed files with 4,969 additions and 4,987 deletions.
18 changes: 0 additions & 18 deletions java/001. Two Sum.java
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
public class Solution {
public int[] twoSum(int[] numbers, int target) {
int[] res = new int[2];
Map map = new HashMap();
for (int i = 0; i < numbers.length; i++) {
map.put(numbers[i], i);
}
for (int i = 0; i < numbers.length; i++) {
int gap = target - numbers[i];
if (map.get(gap) != null && (int) map.get(gap) != i) {
res[0] = i + 1;
res[1] = (int) map.get(gap) + 1;
break;
}
}
return res;
}
}
24 changes: 12 additions & 12 deletions java/002. Add Two Numbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
*/
public class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
return add(l1,l2,true);
return add(l1,l2,true);
}
public ListNode add(ListNode l1, ListNode l2,boolean flag) {
boolean a=l1==null;
boolean b=l2==null;
if (a&&b&&flag) {
return null;
}
int val=(a?0:l1.val)+(b?0:l2.val)+(flag?0:1);
int v=val%10;
boolean f=(v==val);
ListNode answer=new ListNode(v);
answer.next=add(a?null:l1.next,b?null:l2.next,f);
return answer;
boolean a=l1==null;
boolean b=l2==null;
if (a&&b&&flag) {
return null;
}
int val=(a?0:l1.val)+(b?0:l2.val)+(flag?0:1);
int v=val%10;
boolean f=(v==val);
ListNode answer=new ListNode(v);
answer.next=add(a?null:l1.next,b?null:l2.next,f);
return answer;
}
}
30 changes: 15 additions & 15 deletions java/003. Longest Substring Without Repeating Characters.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ public int lengthOfLongestSubstring(String s) {
Map<String,Integer> map=new HashMap<String, Integer>();
List<String> list=new LinkedList<String>();
for (int i = 0; i < s.length(); i++) {
String k=s.substring(i, i+1);
if (map.get(k) != null) {
int n=map.get(k)-map.get(list.get(0))+1;
for (int j = 0; j < n; j++) {
map.remove(list.get(0));
list.remove(0);
}
}
map.put(k, i);
list.add(k);
if (list.size()>answer) {
answer=list.size();
}
}
return answer;
String k=s.substring(i, i+1);
if (map.get(k) != null) {
int n=map.get(k)-map.get(list.get(0))+1;
for (int j = 0; j < n; j++) {
map.remove(list.get(0));
list.remove(0);
}
}
map.put(k, i);
list.add(k);
if (list.size()>answer) {
answer=list.size();
}
}
return answer;
}
}
44 changes: 22 additions & 22 deletions java/006. ZigZag Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ public String convert(String s, int numRows) {
}else{
int k=numRows*2-2;
String[] res=new String[numRows];
for (int i = 0; i < res.length; i++) {
res[i]="";
}
int step=0;
int j=0;
for (int i = 0; i < s.length(); i++) {
step++;
if (step<=numRows) {
j=step;
}else {
j=numRows-(step-numRows);
}
res[j-1]+=s.substring(i, i+1);
if (step==k) {
step=0;
}
}
String result="";
for (int i = 0; i < res.length; i++) {
result+=res[i];
}
return result;
for (int i = 0; i < res.length; i++) {
res[i]="";
}
int step=0;
int j=0;
for (int i = 0; i < s.length(); i++) {
step++;
if (step<=numRows) {
j=step;
}else {
j=numRows-(step-numRows);
}
res[j-1]+=s.substring(i, i+1);
if (step==k) {
step=0;
}
}
String result="";
for (int i = 0; i < res.length; i++) {
result+=res[i];
}
return result;
}
}
}
38 changes: 19 additions & 19 deletions java/007. Reverse Integer.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
public class Solution {
public int reverse(int x) {
String str=String.valueOf(x);
String r="";
int re=0;
if (x<0) {
for (int i = str.length()-1; i >0 ; i--) {
r+=str.substring(i,i+1);
}
r="-"+r;
}else {
for (int i = str.length()-1; i >-1 ; i--) {
r+=str.substring(i,i+1);
}
}
try {
re=Integer.parseInt(r);
} catch (Exception e) {
}
return re;
String r="";
int re=0;
if (x<0) {
for (int i = str.length()-1; i >0 ; i--) {
r+=str.substring(i,i+1);
}
r="-"+r;
}else {
for (int i = str.length()-1; i >-1 ; i--) {
r+=str.substring(i,i+1);
}
}
try {
re=Integer.parseInt(r);
} catch (Exception e) {
}
return re;
}
}
62 changes: 31 additions & 31 deletions java/009. Palindrome Number.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
int n = x;
int a = 0;
int p = 1;
while (x != 0) {
x /= 10;
a++;
p *= 10;
if (a==1) {
p/=10;
}
}
int b = a / 2;
if (b == 0) {
return true;
}
if (x < 0) {
return false;
}
int n = x;
int a = 0;
int p = 1;
while (x != 0) {
x /= 10;
a++;
p *= 10;
if (a==1) {
p/=10;
}
}
int b = a / 2;
if (b == 0) {
return true;
}

for (int i = 0; i < b; i++) {
int begin = n / p;
int end = n % 10;
if (begin != end) {
return false;
} else {
n = n - (begin * p);
p /= 100;
n = (n - end) / 10;
}
}
return true;
}
for (int i = 0; i < b; i++) {
int begin = n / p;
int end = n % 10;
if (begin != end) {
return false;
} else {
n = n - (begin * p);
p /= 100;
n = (n - end) / 10;
}
}
return true;
}
}
86 changes: 43 additions & 43 deletions java/010. Regular Expression Matching.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
public class Solution {
public boolean isMatch(String s, String p) {
if (p.length()==0) {
return s.length()==0;
}
return s.length()==0;
}
if (s.length()==0) {
if (p.length()%2!=0) {
return false;
}
char[] c=p.toCharArray();
for (int i = 1; i < c.length; i+=2) {
if (c[i]!=&#39;*&#39;) {
return false;
}
}
return true;
}
if (p.length()%2!=0) {
return false;
}
char[] c=p.toCharArray();
for (int i = 1; i < c.length; i+=2) {
if (c[i]!=&#39;*&#39;) {
return false;
}
}
return true;
}
int pl=p.length();
int sl=s.length();
String ep=p.substring(pl-1,pl);
if (ep.equals("*")) {
if (p.substring(pl-2,pl-1).equals(".")) {
for (int i = sl-1; i >=0-1; i--) {
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
return true;
}
}
return false;
}else {
String k=p.substring(pl-2,pl-1);
for (int i = sl-1; i >=0; i--) {
String t=s.substring(i,i+1);
if (t.equals(k)) {
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
return true;
}
}else {
return isMatch(s.substring(0, i+1),p.substring(0, pl-2));
}
}
return isMatch("",p.substring(0, pl-2));
}
}else if(ep.equals(".")){
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
}else {
String es=s.substring(sl-1,sl);
if (ep.equals(es)) {
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
}
return false;
}
if (p.substring(pl-2,pl-1).equals(".")) {
for (int i = sl-1; i >=0-1; i--) {
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
return true;
}
}
return false;
}else {
String k=p.substring(pl-2,pl-1);
for (int i = sl-1; i >=0; i--) {
String t=s.substring(i,i+1);
if (t.equals(k)) {
if (isMatch(s.substring(0, i+1),p.substring(0, pl-2))) {
return true;
}
}else {
return isMatch(s.substring(0, i+1),p.substring(0, pl-2));
}
}
return isMatch("",p.substring(0, pl-2));
}
}else if(ep.equals(".")){
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
}else {
String es=s.substring(sl-1,sl);
if (ep.equals(es)) {
return isMatch(s.substring(0, sl-1),p.substring(0, pl-1));
}
return false;
}
}
}
20 changes: 10 additions & 10 deletions java/011. Container With Most Water.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ public int maxArea(int[] height) {
int right=height.length-1;
int ans=(right-left)*Math.min(height[left], height[right]);
while (right>left) {
int water=(right-left)*Math.min(height[left], height[right]);
if (water>ans) {
ans=water;
}
if (height[left]<height[right]) {
left++;
}else {
right--;
}
}
int water=(right-left)*Math.min(height[left], height[right]);
if (water>ans) {
ans=water;
}
if (height[left]<height[right]) {
left++;
}else {
right--;
}
}
return ans;
}
}
Loading

0 comments on commit a6b786d

Please sign in to comment.