
leetcode
leetcode题目总结
Titanium、
这个作者很懒,什么都没留下…
展开
-
回溯法总结
class Solution { //一个映射表,第二个位置是"abc“,第三个位置是"def"。。。 //这里也可以用map,用数组可以更节省点内存 String[] letter_map = {" ","*","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; public List<String> letterCombinations(String digits) { //注意边界条件 if(digits==null |.原创 2021-10-26 11:46:13 · 94 阅读 · 0 评论 -
回溯法——总结(是否包含重复元素,是否全排列)
class Solution { List<List<Integer>> res; List<Integer> path; public List<List<Integer>> permute(int[] nums){ res = new ArrayList<>(); path = new ArrayList<>(); int[] visited = .原创 2021-10-11 16:27:18 · 225 阅读 · 0 评论 -
二分查找模板的应用
class Solution { public int missingNumber(int[] nums) { int i = 0, j = nums.length - 1; while(i <= j) { int m = (i + j) / 2; if(nums[m] == m) i = m + 1; else j = m - 1; } return i;.原创 2021-10-10 23:57:14 · 124 阅读 · 0 评论 -
链表倒数第k个节点
class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode node1 = dummy; ListNode node2 = dummy; while (node1 != null) { .原创 2021-11-17 17:45:30 · 353 阅读 · 0 评论 -
剑指 Offer II 005. 单词长度的最大乘积
给定一个字符串数组 words,请计算当两个字符串 words[i] 和 words[j] 不包含相同字符时,它们长度的乘积的最大值。假设字符串中只包含英语的小写字母。如果没有不包含相同字符的一对字符串,返回 0。class Solution { public int maxProduct(String[] words) { int len = words.length; int[] masks = new int[len]; for(int i=0原创 2021-09-17 11:33:09 · 78 阅读 · 0 评论 -
LRU 缓存机制
class LRUCache { class Node{ int k,v; Node l,r; public Node(int _k, int _v) { k = _k; v = _v; } } int size; Map<Integer, Node> map; Node head, tail; public LRUCache(int .原创 2021-10-15 00:08:14 · 99 阅读 · 0 评论