Skip to content

Commit eeae217

Browse files
committed
commit changes to gh-pages dec 3
1 parent 75b9fc1 commit eeae217

File tree

6 files changed

+113
-2
lines changed

6 files changed

+113
-2
lines changed

_includes/_root/intersection-of-two-linked-lists/README.md

Whitespace-only changes.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) {
7+
* val = x;
8+
* next = null;
9+
* }
10+
* }
11+
*/
12+
public class Solution {
13+
14+
int len(ListNode head){
15+
16+
int len = 0;
17+
ListNode iter = head;
18+
19+
while(iter != null){
20+
21+
len++;
22+
iter = iter.next;
23+
}
24+
25+
return len;
26+
}
27+
28+
ListNode trim(ListNode head, int count){
29+
30+
ListNode iter = head;
31+
32+
while(iter != null && count > 0){
33+
34+
count--;
35+
iter = iter.next;
36+
}
37+
38+
return iter;
39+
}
40+
41+
42+
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
43+
44+
45+
int lenA = len(headA);
46+
int lenB = len(headB);
47+
int min = Math.min(lenA, lenB);
48+
49+
ListNode iterA = trim(headA, lenA - min);
50+
ListNode iterB = trim(headB, lenB - min);
51+
52+
ListNode intersection = null;
53+
54+
55+
while(iterA != null && iterB != null){
56+
57+
if(iterA.val != iterB.val){
58+
intersection = null;
59+
} else if (intersection == null){
60+
intersection = iterA;
61+
}
62+
63+
iterA = iterA.next;
64+
iterB = iterB.next;
65+
}
66+
67+
68+
if (iterA != null || iterB != null){
69+
return null;
70+
}
71+
72+
return intersection;
73+
}
74+
}

_includes/_root/one-edit-distance/README.md

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class Solution {
2+
public boolean isOneEditDistance(String s, String t) {
3+
4+
char[] S = s.toCharArray();
5+
char[] T = t.toCharArray();
6+
7+
// make sure s is always to shorter one
8+
if (S.length > T.length) return isOneEditDistance(t, s);
9+
10+
if (T.length - S.length > 1) return false;
11+
12+
int diff = 0;
13+
14+
int i = 0;
15+
int j = 0;
16+
17+
for(/* void */; i < S.length; i++, j++){
18+
if(S[i] != T[j]){
19+
20+
diff++;
21+
22+
if(diff > 1) return false;
23+
24+
// len(s) + 1 = len(t)
25+
if(S.length != T.length && S[i] == T[j + 1]){
26+
j++; // delete one from T
27+
}
28+
}
29+
}
30+
31+
if (diff == 0){
32+
return j + 1 == T.length;
33+
}
34+
35+
return j == T.length;
36+
}
37+
}

intersection-of-two-linked-lists/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: solution
33
title: Intersection of Two Linked Lists
4-
date: 2014-12-02 13:08:34+08:00
4+
date: 2014-12-02 13:09:51 +0800
55
---
66
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
77
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}

one-edit-distance/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: solution
33
title: One Edit Distance
4-
date: 2014-12-03 00:46:25+08:00
4+
date: 2014-12-03 00:47:41 +0800
55
---
66
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
77
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}

0 commit comments

Comments
 (0)