摘要:
32. 最长有效括号 方法一:动态规划 思路:如果i对应的),则如果i-1一个为( ,则dp[i]=dp[i-2]+2;如果i-1为)查看i-1是否被匹配过。 public class Solution { //动态规划 public int LongestValidParentheses(stri 阅读全文
摘要:
29. 两数相除 #移位 任何正整数都可以用 Math.pow(2,0)+Math.pow(2,1)+...+Math.pow(2,n) 表示。 利用 10/3 =(6+4)/3=2+1=3求解 为了方便计算需要把数都转化为正数,为了防止数值溢出int,转换为long。 public class S 阅读全文
摘要:
https://leetcode-cn.com/problems/trapping-rain-water/ 双指针解法。 1 public class Solution 2 { 3 public int Trap(int[] height) 4 { 5 int size = height.Lengt 阅读全文
摘要:
https://leetcode-cn.com/problems/container-with-most-water/ 双指针解法。 需要理解最大面积 1 public class Solution 2 { 3 //双指针解法,首先要理解 4 public int MaxArea(int[] hei 阅读全文
摘要:
https://leetcode-cn.com/problems/palindrome-number/ 虽然很简单,还是写一下题解吧。 思路1. 首先判断负数和个位数是0但x不等于0的一定不是回文。然后翻转字符串的一半,判断另一半时候和翻转后的相等。注意:121这种奇数位结构。 1 public c 阅读全文