LeetCode_2

3 Longest Substring without repeating characters
  • Hash table may record past result!!
  • left = Math.max(left, map.get(char[right]));

10 Regular Expression Matching
  • Iterative (DP)
  • Recursive

29 Divide Two Integer
  • pos, neg
  • dividend < divisor, return 0
  • use long to deal with over flow
  • recursively find result, sum += sum, multiple += multiple

30. Substring with Concatenation of All Words
  • Two pointer + hash table + sliding window

  1. Longest Valid Parentheses
  • method 1: Stack, greedy
  • method 2: DP

37 Sudoku Solver
  • DFS, backtracking
  • Only need to check the position of new added number is valid or not

  1. Pow(x, n)
  • x = 0, n = 0, n < 0, n % 2
  • n OverFlow!!!

218 The Skyline Problem
  • Sort + PQ


168 Excel Sheet Column Title
  • Shift -1 EACH TIME to get base 26
  • 52 = AZ = (A' + 1) * 26 + (Z' + 1) * 1

215 Kth Largest Element in an Array
  • Mind the partition fiction.
    • nums[right] <= pivot)
    • return helper(nums, left + 1, r, k);

140 Word Break II
  • Map<String, List<String>> dp save results

283 Moving zeros
  • Do not focus on doing swap.
  • Simply replace number!

57 Insert Interval
  • mark down the insert position.

60 Permutation sequence
  • factorial, remainder, used[]

68 Text Justification
  • Last line should be left-justified.
  • remainder spaces will be given to the first several space.

85 Maximal Rectangle
  • Method 1. Utilize maximal rectangle in histogram
  • Method 2. DP[], left[], right[], height[]

87 Scramble String
  • recursion + cache

89 Gray Code
  • Find the law!

93 Parse IP Address
  • if(s.length()>3 || s.length()==0 || (s.charAt(0)=='0' && s.length()>1) || Integer.parseInt(s)>255)

95 Unique Binary Search Tree II
  • DP for each level
  • Build right Tree with offset.

97 Interleaving String
  • Cache + Recursion

99 Recover Binary Search Tree
  • Inorder Traversal to find the invalid element

115 Distinct Subsequences
  • dp

125 Word Ladder II
  • bfs to build neighbors and distance map
  • dos find the result.

132 Palindrome Partitioning II
  • dp
  • odd length and even length palindrome, spread from the center.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值