File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
longest-consecutive-sequence Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int rob (int [] nums ) {
3+ int money = 0 ;
4+ for (int i = 0 ; i < nums .length ; i ++) {
5+ if (i % 2 == 0 ) {
6+ money += nums [i ];
7+ }
8+ }
9+ return money ;
10+ }
11+ }
Original file line number Diff line number Diff line change 11import java .util .HashSet ;
22
3- class ymir0804 {
3+ class Solution {
44 public int longestConsecutive (int [] nums ) {
55 HashSet <Integer > numsSet = new HashSet <>();
66 int maxNum = 0 ;
7- for (int num : nums ) {
7+ for (int num : nums ) {
88 numsSet .add (num );
99 }
1010
11- if (numsSet .isEmpty ()) {
11+ if (numsSet .isEmpty ()) {
1212 return 1 ;
1313 } else if (numsSet .size () == 1 ) {
1414 return 0 ;
1515 }
1616
17- for (int num : numsSet ) {
17+ for (int num : numsSet ) {
1818 boolean isStartPoint = !numsSet .contains (num - 1 );
1919 if (isStartPoint ) {
2020 int current = num ;
2121 int length = 1 ;
22- while (numsSet .contains (++current )) {
22+ while (numsSet .contains (++current )) {
2323 length ++;
2424 }
25- if (length > maxNum ) {
25+ if (length > maxNum ) {
2626 maxNum = length ;
2727 }
2828 }
2929 }
3030 return maxNum ;
31- }
32- }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments