Skip to content

Commit 2b24f02

Browse files
committed
my own leetcode view;
1 parent d54abce commit 2b24f02

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

src/me/codebase/leetcode/Test.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package me.codebase.leetcode;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Created by chendong on 2017/12/13.
8+
*/
9+
public class Test {
10+
11+
12+
public static void main(String[] args) {
13+
Integer[] arr1 = {1, 2, 3};
14+
Integer[] arr2 = {2, 3, 4};
15+
16+
int mid1 = arr1.length / 2;
17+
int mid2 = arr2.length / 2;
18+
}
19+
20+
/* public static int lengthOfLongestSubstring(String s) {
21+
int len;
22+
if (s == null || (len = s.length()) == 0) return 0;
23+
int preP = 0, max = 0;
24+
int[] hash = new int[128];
25+
for (int i = 0; i < len; ++i) {
26+
char c = s.charAt(i);
27+
if (hash[c] > preP) {
28+
preP = hash[c];
29+
}
30+
int l = i - preP + 1;
31+
hash[c] = i + 1;
32+
if (l > max) max = l;
33+
}
34+
return max;
35+
}
36+
*/
37+
private static String distinct(String str) {
38+
Map<Character, Integer> map = new HashMap<>();
39+
char[] chars = str.toCharArray();
40+
for (int i = 0; i < chars.length; i++) {
41+
42+
if (map.get(chars[i]) != null)
43+
map.put(chars[i], i - map.get(chars[i]));
44+
else
45+
map.put(chars[i], i);
46+
}
47+
return null;
48+
}
49+
50+
51+
52+
53+
/*
54+
private static String findSubString(String str, int index) {
55+
char[] chars = str.toCharArray();
56+
int l = 1;
57+
for (int i = index; i < chars.length; i++) {
58+
if (chars[i] != chars[i++]) {
59+
l++;
60+
}else break;
61+
}
62+
return String.valueOf()
63+
}
64+
*/
65+
66+
67+
}

src/me/codebase/leetcode/_002.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package me.codebase.leetcode;
2+
3+
/**
4+
* Created by chendong on 2017/12/13.
5+
*/
6+
public class _002 {
7+
8+
private static Node add(Node n1, Node n2) {
9+
int over = 0;
10+
Node root = null;
11+
Node node = null;
12+
while (n1 != null && n2 != null) {
13+
Node n = new Node(0);
14+
n.val = (n1.val + n2.val + over) % 10;
15+
over = (n1.val + n2.val) / 10;
16+
n1 = n1.next;
17+
n2 = n2.next;
18+
if (node == null) {
19+
node = n;
20+
root = node;
21+
} else
22+
node.next = n;
23+
if (node.next != null)
24+
node = node.next;
25+
}
26+
return root;
27+
}
28+
29+
static class Node {
30+
int val;
31+
Node next;
32+
33+
public Node(int val) {
34+
this.val = val;
35+
}
36+
}
37+
38+
}

0 commit comments

Comments
 (0)