Skip to content

Commit 9b9b577

Browse files
author
freemanzhang
committed
init impl
1 parent f069d44 commit 9b9b577

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Fight towards 1000 commits !!!
1+
# My whiteboard coding interview operating system !!!
22
<!-- MarkdownTOC -->
33

44
- [Typical whiteboard coding workflow](#typical-whiteboard-coding-workflow)
@@ -22,7 +22,6 @@
2222
- [Leetcode pros and cons](#leetcode-pros-and-cons)
2323
- [Interview Java pros and cons](#interview-java-pros-and-cons)
2424
- [Java language](#java-language)
25-
- [Characteristics of Object oriented](#characteristics-of-object-oriented)
2625
- [Java vs C++](#java-vs-c)
2726
- [Access modifiers](#access-modifiers)
2827
- [Stack vs heap vs static area](#stack-vs-heap-vs-static-area)
@@ -67,8 +66,7 @@
6766
- [String](#string)
6867
- [Why String is immutable or final](#why-string-is-immutable-or-final)
6968
- [String vs StringBuilder vs StringBuffer](#string-vs-stringbuilder-vs-stringbuffer)
70-
- [String reverse](#string-reverse)
71-
- [Encode and decode](#encode-and-decode)
69+
- [Word reverse](#word-reverse)
7270
- [Palindrome](#palindrome)
7371
- [Collections](#collections)
7472
- [Iterator](#iterator)
@@ -163,8 +161,8 @@
163161
- [Union find](#union-find)
164162
- [Greedy](#greedy)
165163
- [Dynamic-programming](#dynamic-programming)
166-
- [Online IDE templates](#online-ide-templates)
167-
- [References](#references)
164+
- [Online IDE templates](#online-ide-templates)
165+
- [References](#references)
168166

169167
<!-- /MarkdownTOC -->
170168

@@ -346,6 +344,7 @@
346344
* I am used to good words. When interviewer doubts/challenges me, I become kind of sad. Always stay in calm and smiles.
347345
* Give myself a little break between interviews. Either sit down or drink some beverages.
348346
* When interviewers keep interrupting me, do not be nervous. They are trying to help me!!! Always stay in calm and take their hints. No matter whether I could finish my current solution. Communication is the most important thing.
347+
* Preparing interview: What really matters is how many times you practice the leetcode problem, rather than how long you spend during a single practice round.
349348

350349
#### Whiteboard coding pros and cons
351350
* Pros
@@ -415,7 +414,6 @@
415414
* Linkedhashset could not be iterated reversely
416415

417416
### Java language
418-
#### Characteristics of Object oriented
419417

420418
#### Java vs C++
421419

@@ -1155,9 +1153,9 @@ private List<List<Integer>> kSum( int kVal, int target, int startIndex, int[] nu
11551153
| Thread safe | Yes | No | Yes |
11561154
| Performance | Fast | Fast | very slow|
11571155

1158-
##### String reverse
1156+
##### Word reverse
1157+
11591158

1160-
##### Encode and decode
11611159

11621160
##### Palindrome
11631161
* Several ways to solve the Longest palindrome substring problem
@@ -3286,7 +3284,7 @@ public int houseRobber_RollingArray( int[] A )
32863284
* answer: varies with problems
32873285
+ Examples: Backpack I-VI (Lintcode), K Sum (Lintcode), Minimum adjustment cost (Lintcode)
32883286

3289-
#### Online IDE templates
3287+
### Online IDE templates
32903288
* Coderpad
32913289

32923290
```java
@@ -3323,7 +3321,7 @@ public class Solution
33233321
}
33243322
```
33253323

3326-
#### References
3324+
### References
33273325
* [Java-success.com](http://www.java-success.com/)
33283326
* [Massive tech interview](http://massivetechinterview.blogspot.com/)
33293327
* [Java best practices](http://www.javapractices.com/home/HomeAction.do)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package math;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/*
7+
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
8+
9+
Find all the elements that appear twice in this array.
10+
11+
Could you do it without extra space and in O(n) runtime?
12+
13+
Example:
14+
Input:
15+
[4,3,2,7,8,2,3,1]
16+
17+
Output:
18+
[2,3]
19+
* */
20+
21+
public class FindAllDuplicatesInAnArray
22+
{
23+
public List<Integer> findDuplicates( int[] nums )
24+
{
25+
List<Integer> result = new ArrayList<>();
26+
for ( int i = 0; i < nums.length; i++ )
27+
{
28+
int index = Math.abs( nums[i] );
29+
if ( nums[index-1] > 0 )
30+
{
31+
nums[index-1] = - nums[index-1];
32+
}
33+
else
34+
{
35+
result.add( Math.abs( nums[i] ) );
36+
}
37+
}
38+
return result;
39+
}
40+
}

0 commit comments

Comments
 (0)