Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit532fba0

Browse files
add 1429
1 parentc915d76 commit532fba0

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ _If you like this project, please leave me a star._ ★
298298
|1436|[Destination City](https://leetcode.com/problems/destination-city/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1436.java)||Easy|String|
299299
|1432|[Max Difference You Can Get From Changing an Integer](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1432.java)||Medium|String|
300300
|1431|[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1431.java),[C++](../master/cpp/_1431.cpp)||Easy|Array|
301+
|1429|[First Unique Number](https://leetcode.com/problems/first-unique-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1429.java)||Medium|Array, HashTable, Design, Data Streams|
301302
|1428|[Leftmost Column with at Least a One](https://leetcode.com/problems/leftmost-column-with-at-least-a-one/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1428.java)||Medium|Array|
302303
|1427|[Perform String Shifts](https://leetcode.com/problems/perform-string-shifts/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1427.java)||Easy|Array, Math|
303304
|1426|[Counting Elements](https://leetcode.com/problems/counting-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1426.java)||Easy|Array|
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashSet;
4+
importjava.util.LinkedHashSet;
5+
importjava.util.Set;
6+
7+
publicclass_1429 {
8+
publicstaticclassSolution1 {
9+
/**
10+
* Credit: https://leetcode.com/problems/first-unique-number/discuss/602698/Java-Easy-Set-O(1)
11+
* <p>
12+
* LinkedHashSet is a handy data structure to help preserve the order of all unique elements.
13+
*/
14+
publicstaticclassFirstUnique {
15+
16+
Set<Integer>uniqSet;
17+
Set<Integer>nonUniqSet;
18+
19+
publicFirstUnique(int[]nums) {
20+
uniqSet =newLinkedHashSet<>();
21+
nonUniqSet =newHashSet<>();
22+
for (intnum :nums) {
23+
add(num);
24+
}
25+
}
26+
27+
publicintshowFirstUnique() {
28+
if (!uniqSet.isEmpty()) {
29+
returnuniqSet.iterator().next();
30+
}
31+
return -1;
32+
}
33+
34+
publicvoidadd(intvalue) {
35+
if (uniqSet.contains(value)) {
36+
uniqSet.remove(value);
37+
nonUniqSet.add(value);
38+
}
39+
if (!nonUniqSet.contains(value)) {
40+
uniqSet.add(value);
41+
}
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp