File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {boolean }
4+ */
5+ var containsDuplicate = function ( nums ) {
6+ const set = new Set ( nums ) ;
7+ return set . size !== nums . length ;
8+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ var maxSubArray = function ( nums ) {
6+ let maxSum = nums [ 0 ] ;
7+ let max = nums [ 0 ] ;
8+
9+ for ( let i = 1 ; i < nums . length ; i ++ ) {
10+ max = Math . max ( nums [ i ] , max + nums [ i ] ) ;
11+ maxSum = Math . max ( max , maxSum ) ;
12+ }
13+ return maxSum ;
14+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @param {number } target
4+ * @return {number[] }
5+ */
6+ var twoSum = function ( nums , target ) {
7+ const map = new Map ( ) ;
8+
9+ for ( let i = 0 ; i < nums . length ; i ++ ) {
10+ const num = target - nums [ i ] ;
11+ if ( map . has ( num ) ) {
12+ return [ map . get ( num ) , i ] ;
13+ }
14+ map . set ( nums [ i ] , i ) ;
15+ }
16+
17+ return [ ] ;
18+ } ;
You can’t perform that action at this time.
0 commit comments