Skip to content

Commit 187eb93

Browse files
committed
minor upate
1 parent 9af6c34 commit 187eb93

18 files changed

+1823
-1561
lines changed

Java/Intersection of Two Arrays.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
E
2+
1533542058
3+
tags: Hash Table, Two Pointers, Binary Search, Sort
24

3-
方法1: 用到hashset找unique && duplicate: O(m+n)
4-
方法2: 可以用binary search 找数字. Note:binary search一定需要array sorted: nLog(m)
5+
- 方法1: 用到hashset找unique && duplicate: O(m+n)
6+
- 方法2: 可以用binary search 找数字. Note:binary search一定需要array sorted: nLog(m)
57

68
```
79
/*
@@ -27,19 +29,19 @@ public int[] intersection(int[] nums1, int[] nums2) {
2729
if (nums1 == null || nums2 == null || nums1.length == 0 || nums2.length == 0) {
2830
return new int[0];
2931
}
30-
final Set<Integer> unionSet = new HashSet<>();
31-
final Set<Integer> resultSet = new HashSet<>();
32-
for (final int num: nums1) {
32+
Set<Integer> unionSet = new HashSet<>();
33+
Set<Integer> resultSet = new HashSet<>();
34+
for (int num: nums1) {
3335
unionSet.add(num);
3436
}
35-
for (final int num: nums2) {
37+
for (int num: nums2) {
3638
if (unionSet.contains(num)) {
3739
resultSet.add(num);
3840
}
3941
}
4042
int i = 0;
41-
final int[] result = new int[resultSet.size()];
42-
for (final int num: resultSet) {
43+
int[] result = new int[resultSet.size()];
44+
for (int num: resultSet) {
4345
result[i++] = num;
4446
}
4547
return result;

Java/Roman to Integer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
E
2+
1533541868
3+
tags: Math, String
24

35
熟悉罗马字母规则
46
1. 'I V X L C D M' 分别代表的数字

Java/Strobogrammatic Number.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
E
2+
1533542248
3+
tags: Hash Table, Math
24

35
根据题意枚举, 再根据规则basic implementation
46

7+
#### Alter input
8+
9+
#### HashTable + Two Pointer
10+
511
```
612
/*
713
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

Java/Valid Parentheses.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
E
2+
1533542429
3+
tags: String, Stack
24

35
剥皮过程解铃还须系铃人
46
左边的外皮'{['在stack底部
57
右边的外皮应该和stack顶上的左外皮一一对应
68

7-
8-
99
```
1010
/*
1111
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
@@ -19,17 +19,12 @@
1919

2020
//lock will be unlocked by the same key
2121
//put in stack. when '),],}' appears, check stack.top() to make sure they are good match
22-
/*
23-
Use stack to hold the parentheses (head/tail) and remove them accordingly.
24-
*/
22+
// Use stack to hold the parentheses (head/tail) and remove them accordingly.
2523
class Solution {
2624
public boolean isValid(String s) {
27-
if (s == null || s.length() == 0) {
28-
return true;
29-
}
30-
final char[] charArray = s.toCharArray();
31-
final Stack<Character> stack = new Stack<Character>();
32-
for (char c : charArray) {
25+
if (s == null || s.length() == 0) return true;
26+
final Stack<Character> stack = new Stack<>();
27+
for (char c : s.toCharArray()) {
3328
if (c == '(' || c == '{' || c == '[') {
3429
stack.add(c);
3530
} else if (c == ')' || c == '}' || c == ']') {
@@ -51,7 +46,6 @@ public boolean isValid(String s) {
5146
}
5247
}
5348

54-
5549
/*
5650
Thoughts:
5751
Did this on Leetcode. Think about how do we naturally check it?

Java/Zigzag Iterator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
Follow up: What if you are given k 1d vectors? How well can your code be extended to such cases?
1818
1919
Clarification for the follow up question - Update (2015-09-18):
20-
The "Zigzag" order is not clearly defined and is ambiguous for k > 2 cases. If "Zigzag" does not look right to you, replace "Zigzag" with "Cyclic". For example, given the following input:
20+
The "Zigzag" order is not clearly defined and is ambiguous for k > 2 cases.
21+
If "Zigzag" does not look right to you, replace "Zigzag" with "Cyclic".
22+
For example, given the following input:
2123
2224
[1,2,3]
2325
[4,5,6,7]

0 commit comments

Comments
 (0)