This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function uniquePaths(m: number, n: number): number { | |
| let row: number[] = new Array(n).fill(1); | |
| for (let i = 1; i < m; i++) { | |
| let nextRow: number[] = new Array(n).fill(1); | |
| for (let j = n-2; j>=0; j--) { | |
| nextRow[j] = nextRow[j + 1] + row[j] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function canPartition(nums: number[]): boolean { | |
| const sum = nums.reduce((acc, cur) => acc + cur, 0); | |
| if (sum % 2 !== 0) { | |
| return false; | |
| } | |
| // промеждуточные суммы | |
| let dp: Set<number> = new Set(); | |
| dp.add(0) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function lengthOfLIS(nums: number[]): number { | |
| const n = nums.length; | |
| const dp: number[] = new Array(n).fill(1); | |
| for(let i = n - 1; i >= 0; i--) { | |
| for(let j = i +1; j < n; j++) { | |
| if(nums[i] < nums[j]) { | |
| dp[i] = Math.max(dp[i], dp[j] + 1) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function wordBreak(s: string, wordDict: string[]): boolean { | |
| let dp: boolean[] = new Array(s.length + 1).fill(false) | |
| dp[s.length] = true; | |
| for(let i = s.length - 1; i >= 0; i--) { | |
| for(let w of wordDict) { | |
| if( | |
| i + w.length <= s.length && | |
| s.substring(i, i + w.length) === w | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function maxProduct(nums: number[]): number { | |
| let res = nums[0] | |
| let curMax = nums[0]; | |
| let curMin = nums[0]; | |
| for (let i = 1; i < nums.length; i ++) { | |
| let n = nums[i] | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function coinChange(coins: number[], amount: number): number { | |
| let dp: number[] = new Array(amount+1).fill(amount+1); | |
| dp[0] = 0; | |
| for(let a = 1; a <= amount; a++) { | |
| for(let c of coins) { | |
| if(a - c >= 0) { | |
| dp[a] = Math.min(dp[a], 1 + dp[a-c]) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function numDecodings(s: string): number { | |
| const dp: { | |
| [key: number]: number | |
| } = { | |
| [s.length] : 1 | |
| } | |
| function dfs(i: number): number { | |
| // base cases | |
| if (i in dp) { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function countSubstrings(s: string): number { | |
| let res = 0; | |
| for(let i = 0; i < s.length; i++) { | |
| // не четные | |
| res+= countPalindrome(s, i, i); | |
| // четное | |
| res+= countPalindrome(s, i, i+ 1); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /** | |
| * @param {number[]} nums | |
| * @return {number} | |
| */ | |
| var rob = function(nums) { | |
| return Math.max(nums[0], rob(nums.slice(1)), rob(nums.slice(0, -1))) | |
| function rob(nums) { | |
| let curSkip = 0; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /** | |
| * @param {number[]} nums | |
| * @return {number} | |
| */ | |
| var rob = function(nums) { | |
| let curSkip = 0; | |
| let curRob = 0; | |
| for (const n of nums) { | |
| const temp = Math.max(n + curSkip, curRob) | |
| curSkip = curRob | 
NewerOlder