File tree 1 file changed +16
-12
lines changed
scripts/algorithms/O/Optimal Division
1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 9 ms (Top 33.5%) | Memory: 41.11 MB (Top 16.7%)
2
+
1
3
class Solution {
2
4
public String optimalDivision (int [] nums ) {
3
- if (nums .length == 1 ){
5
+
6
+ if (nums .length ==1 ){
4
7
return nums [0 ] + "" ;
5
- }
6
- if (nums .length == 2 ){
7
- StringBuilder sb = new StringBuilder ();
8
- sb .append (nums [0 ]+"/" +nums [1 ]);
8
+ }else if (nums .length ==2 ){
9
+ StringBuilder sb =new StringBuilder ();
10
+ sb .append (nums [0 ] + "/" + nums [1 ]);
9
11
return sb .toString ();
10
12
}
11
- StringBuilder sb = new StringBuilder ();
12
- sb .append (nums [0 ]);
13
- sb .append ("/(" );
14
- for (int i = 1 ; i < nums .length -1 ; i ++){
15
- sb .append (nums [i ]+"/" );
13
+
14
+ StringBuilder sb =new StringBuilder ();
15
+ sb .append (nums [0 ]);
16
+ sb .append ("/(" );
17
+ for (int i =1 ;i <nums .length -1 ;i ++){
18
+ sb .append (nums [i ] + "/" );
16
19
}
17
- sb .append (nums [nums .length -1 ] +")" );
20
+ sb .append (nums [nums .length -1 ] + ")" );
21
+
18
22
return sb .toString ();
19
23
}
20
- }
24
+ }
You can’t perform that action at this time.
0 commit comments