摘要:
最长回文子串 题目 中等 和最长回文子序列类似 自己的做法: class Solution { public String longestPalindrome(String s) { int len = s.length(); int max = 1; int left = 0, right = 0 阅读全文
摘要:
斐波那契数 题目 简单 class Solution { public int fib(int n) { if (n < 2) return n; int a = 0, b = 1, c = 0; for (int i = 1; i < n; i++) { c = a + b; a = b; b = 阅读全文
摘要:
分发饼干 题目 简单 这里的局部最优就是大饼干喂给胃口大的,充分利用饼干尺寸喂饱一个,全局最优就是喂饱尽可能多的小孩。 class Solution { // 思路:优先考虑胃口,先喂饱大胃口 public int findContentChildren(int[] g, int[] s) { Ar 阅读全文
摘要:
组合 题目 中等 class Solution { List<List<Integer>> result = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> co 阅读全文
摘要:
反转字符串 题目 简单 class Solution { public void reverseString(char[] s) { int l = 0; int r = s.length - 1; while (l < r) { s[l] ^= s[r]; //构造 a ^ b 的结果,并放在 a 阅读全文