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

Commit caa2ca1

Browse files
updated
1 parent eb68eba commit caa2ca1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

‎AllQuestions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ tree.
612612
The power set of a set is the set of all its subsets. Write a function that,
613613
given a set, generates its power set.
614614

615-
For example, given the set {1, 2, 3}, it should return {{}, {1}, {2}, {3}, {1,
616-
2}, {1, 3}, {2, 3}, {1, 2, 3}}.
615+
For example, given the set `{1, 2, 3}`, it should return `{{}, {1}, {2}, {3}, {1,
616+
2}, {1, 3}, {2, 3}, {1, 2, 3}}`.
617617

618618
You may also use a list or array to represent a set.
619619

‎build.gradle‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ repositories {
1313

1414
dependencies {
1515
testImplementation('org.junit.jupiter:junit-jupiter:5.4.2')
16+
17+
1618
}

‎src/main/java/in/ashwanik/dcp/problems/p91_120/p99/Solution.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ int getLongestConsecutiveSequenceLength(int[] numbers) {
1717
int max = 0;
1818
for (int n : numbers) {
1919
int k = n;
20-
int count = 1;
21-
while (set.contains(++k)) {
22-
count++;
20+
if (!set.contains(k - 1)) {
21+
int count = 1;
22+
while (set.contains(++k)) {
23+
count++;
24+
}
25+
max = Math.max(max, count);
2326
}
24-
max = Math.max(max, count);
2527
}
2628
return max;
2729
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /