File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .ArrayList ;
2
+ import java .util .Arrays ;
3
+ import java .util .HashSet ;
4
+ import java .util .List ;
5
+ import java .util .Set ;
6
+
7
+ class Solution {
8
+ public List <List <Integer >> threeSum (int [] nums ) {
9
+ Arrays .sort (nums );
10
+
11
+ Set <List <Integer >> answer = new HashSet <>();
12
+
13
+ for (int i = 0 ; i < nums .length - 2 ; i ++) {
14
+ int left = i + 1 ;
15
+ int right = nums .length - 1 ;
16
+
17
+ while (left < right ) {
18
+ int sum = nums [i ] + nums [left ] + nums [right ];
19
+
20
+ if (sum < 0 ) {
21
+ left ++;
22
+ } else if (sum > 0 ) {
23
+ right --;
24
+ } else {
25
+ answer .add (List .of (nums [i ], nums [left ], nums [right ]));
26
+
27
+ left ++;
28
+ right --;
29
+ }
30
+ }
31
+ }
32
+
33
+ return new ArrayList <>(answer );
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int climbStairs (int n ) {
3
+ int [] stepCount = new int [n + 1 ];
4
+
5
+ if (n == 1 ) {
6
+ return 1 ;
7
+ }
8
+
9
+ stepCount [1 ] = 1 ;
10
+ stepCount [2 ] = 2 ;
11
+ for (int i = 3 ; i <= n ; i ++) {
12
+ stepCount [i ] = stepCount [i - 1 ] + stepCount [i - 2 ];
13
+ }
14
+
15
+ return stepCount [n ];
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .Arrays ;
2
+
3
+ class Solution {
4
+ public boolean isAnagram (String s , String t ) {
5
+ char [] sChar = s .toCharArray ();
6
+ char [] tChar = t .toCharArray ();
7
+
8
+ Arrays .sort (sChar );
9
+ Arrays .sort (tChar );
10
+
11
+ return Arrays .equals (sChar , tChar );
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments