File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number } n
3+ * @return {number }
4+ */
5+ var climbStairs = function ( n ) {
6+ // Make an array to store each number of ways
7+ let steps = new Array ( n ) ;
8+ // When stairs is 1 and 2 has exact number 1 and 2
9+ steps [ 1 ] = 1 ;
10+ steps [ 2 ] = 2 ;
11+ // Iterate to get ways of 3 more steps stairs
12+ // ((n-1) + (n-2))
13+ for ( let i = 3 ; i <= n ; i ++ ) {
14+ steps [ i ] = steps [ i - 1 ] + steps [ i - 2 ] ;
15+ }
16+ return steps [ n ] ;
17+ } ;
18+
19+ // TC: O(n)
20+ // SC: O(n)
Original file line number Diff line number Diff line change 1+ /**
2+ * Definition of Interval:
3+ * class Interval {
4+ * constructor(start, end) {
5+ * this.start = start;
6+ * this.end = end;
7+ * }
8+ * }
9+ */
10+
11+ class Solution {
12+ /**
13+ * @param {Interval[] } intervals
14+ * @returns {boolean }
15+ */
16+ canAttendMeetings ( intervals ) {
17+ // Sort the intervals based on their start times
18+ intervals . sort ( ( a , b ) => a . start - b . start ) ;
19+
20+ for ( let i = 0 ; i < intervals . length - 1 ; i ++ ) {
21+ // Check if the current interval overlaps with the next interval
22+ if ( intervals [ i ] . end > intervals [ i + 1 ] . start ) {
23+ return false ;
24+ }
25+ }
26+
27+ return true ;
28+ }
29+ }
30+
31+ // TC: O(nlogn)
32+ // SC: O(1)
You can’t perform that action at this time.
0 commit comments