摘要:
Wiggle Subsequence 最长扭动子序列 思路1:动态规划。状态dp[i]表示以nums[i]为末尾的最长wiggle子序列的长度。时间是O(n^2). 1 public class Solution { 2 public int wiggleMaxLength(int[] nums) 阅读全文
摘要:
Different Ways to Add Parentheses 加括号的不同方式 思路:分治地求出一个运算符的左边部分和右边部分的结果,将它们两两组合运算。优化的方式是用一个hash表记录所有字串的中间结果,避免重复计算。 1 public class Solution { 2 Map<Stri 阅读全文
摘要:
Bulb Switcher 灯泡开关 思路:除了平方数以外,其他所有位置的灯泡最终都被开关了偶数次,因此最终都为0。问题等价于求1~n中平方数的个数。 1 public class Solution { 2 public int bulbSwitch(int n) { 3 return (int)M 阅读全文