文章分类 -  算法题

摘要:不同的二叉搜索树 https://leetcode.cn/problems/unique-binary-search-trees/solutions/6693/hua-jie-suan-fa-96-bu-tong-de-er-cha-sou-suo-shu-b/ class Solution { p 阅读全文
posted @ 2023-03-17 22:17 黄一洋 阅读(10) 评论(0) 推荐(0)
摘要:字母异位词分组 将字符串变为 字符数组后,对这个字符数组进行排序,再拼为字符串作为 GroupBy 算子的 key class Solution { public List<List<String>> groupAnagrams(String[] strs) { return new ArrayLi 阅读全文
posted @ 2023-03-17 22:17 黄一洋 阅读(19) 评论(0) 推荐(0)
摘要:分割回文串 难点: 切割问题 可以抽象为组合问题 如何模拟那些切割线 切割问题中递归如何终止 在递归循环中如何截取子串 如何判断回文 package day.d0317; import java.util.ArrayList; import java.util.Deque; import java. 阅读全文
posted @ 2023-03-17 22:17 黄一洋 阅读(16) 评论(0) 推荐(0)
摘要:二分查找 注意边界情况 package day.d0315; /** * @author hdbing * 二分查找 * @create 2023-03-15 15:52 */ public class T01 { public static int search(int[] nums, int t 阅读全文
posted @ 2023-03-17 22:17 黄一洋 阅读(17) 评论(0) 推荐(0)
摘要:组合 class Solution { List<List<Integer>> res=new ArrayList<>(); LinkedList<Integer> path=new LinkedList<>(); public List<List<Integer>> combine(int n, 阅读全文
posted @ 2023-03-17 22:17 黄一洋 阅读(40) 评论(0) 推荐(0)
摘要:Excel 表列序号 从后往前 乘26 class Solution { public int titleToNumber(String columnTitle) { int len = columnTitle.length(); int num = 0; int res=0; for(int i= 阅读全文
posted @ 2023-03-08 22:21 黄一洋 阅读(22) 评论(0) 推荐(0)
摘要:股票问题01 121. 买卖股票的最佳时机 - 力扣(Leetcode) class Solution { public int maxProfit(int[] prices) { int minPrice=prices[0]; int maxProfit=0; for(int price:pric 阅读全文
posted @ 2023-03-07 21:39 黄一洋 阅读(33) 评论(0) 推荐(0)
摘要:排序算法分类 非线性时间 比较类 交换 冒泡排序 快速排序 插入 插入排序 希尔排序 选择 选择排序 堆排序 归并 归并排序 线性时间 非比较类:计数排序、桶排序、基数排序 性能评估术语 稳定:如果a原本在b前面,而a=b时,排序之后a仍然在b的前面 不稳定:如果a原本在b的前面,而a=b时,排序之 阅读全文
posted @ 2023-03-06 21:24 黄一洋 阅读(45) 评论(0) 推荐(0)
摘要:最小路径和 思路:动态规划,$dp[i][j]$ 保存 $(i,\ j)$ 时最小路径值 class Solution { public int minPathSum(int[][] grid) { for(int i=0;i<grid.length;i++){ for(int j=0;j<grid 阅读全文
posted @ 2023-03-05 17:52 黄一洋 阅读(21) 评论(0) 推荐(0)
摘要:电话号码的字母组合 17. 电话号码的字母组合 - 力扣(Leetcode) 思路:1. 回溯,2. 队列 class Solution: def letterCombinations(self, digits: str) -> List[str]: if not digits: return [] 阅读全文
posted @ 2023-03-05 14:06 黄一洋 阅读(22) 评论(0) 推荐(0)
摘要:环形链表 II 思路:快慢指针 根据,设起点到入点为a,圈为b个节点 f=2s (快指针每次2步,路程刚好2倍) f = s + nb (首次相遇时,刚好多走了n圈) 推出:s = nb,即快指针比慢指针在圈里多走了n圈,这样只需要再走a步即可到达入点 从head结点走到入环点需要走 : a + n 阅读全文
posted @ 2023-03-05 14:06 黄一洋 阅读(21) 评论(0) 推荐(0)
摘要:1. 滑动窗口 剑指 Offer 30. 包含min函数的栈 /** * 剑指 Offer 30. 包含min函数的栈 */ class minStack { Stack<Integer> A, B; public minStack() { A = new Stack<>(); B = new St 阅读全文
posted @ 2023-02-28 22:39 黄一洋 阅读(17) 评论(0) 推荐(0)