自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(421)
  • 收藏
  • 关注

原创 【leetcode每日刷题】214. 最短回文串

给定一个字符串 s,你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。示例1:输入: "aacecaaa"输出: "aaacecaaa"示例 2:输入: "abcd"输出: "dcbabcd"解法:KMP算法假设添加的字符串为sadd,则sadd+s为回文字符串,s = shead + stail;stail = sadd。查找最长回文前缀shead,匹配方式shead和s进行匹配class Solution { publi.

2020-08-29 17:51:55 929 1

原创 【读源码】HashMap

1、结构实现了Map接口,继承AbstractMappublic class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable2、hash值的计算获得key的hashCode,然后与无符号右移16位的h异或,即为高16位和低16位异或。//来自Object的native方法hashCode()public native i.

2020-08-16 00:14:21 277

原创 【面试指南】打气球的最大分数

package interview;public class HitBalloon { public static void main(String[] args) { int[] arr = { 3, 2, 5 }; int result = maxProfit(arr); System.out.println(result); } public static int maxProfit(int[] arr) { .

2020-08-11 10:27:16 431

原创 【leetcode每日刷题】355. 设计推特

https://leetcode-cn.com/problems/design-twitter/import java.util.HashMap;import java.util.HashSet;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;c...

2020-04-13 09:21:01 245

原创 【leetcode每日刷题】22. 括号生成

import java.util.LinkedList;import java.util.List;class Solution { public List<String> generateParenthesis(int n) { List<String> ans = new LinkedList<>(); gene...

2020-04-09 12:02:08 192

原创 【leetcode每日刷题】316. 去除重复字母

https://leetcode-cn.com/problems/remove-duplicate-letters/使用三个数据结构:map存放字符出现的最后位置;set存放栈中的非重复字符;stack存放结果的可能序列。1、将多有字符出现的最后位置放入map中2、遍历字符串,如果遍历的序列中已经将字符放入栈中,则比较栈顶元素的序列,否则直接放入,已经在栈中的元素已经是最小字典序列。...

2020-04-08 13:43:33 295

原创 【leetcode每日刷题】47. Permutations II

https://leetcode.com/problems/permutations-ii/package leetcode;/** * 有重复元素的排列组合 * 回溯法 */import java.util.ArrayList;import java.util.Arrays;import java.util.List;class num47 { public Li...

2020-04-01 12:19:15 190

原创 【leetcode每日刷题】236. Lowest Common Ancestor of a Binary Tree

https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/1、创建stack,和map,stack用于遍历路径,map用于保存遍历的每个节点的父节点,直到p和q的父节点都已经遍历到。2、创建ancestor set,存储p节点含自己的所有父节点3、回溯q节点的所有父节点,直到它是可以在set中找到的。如果...

2020-03-30 22:21:40 164

原创 【leetcode每日刷题】437. Path Sum III

https://leetcode.com/problems/path-sum-iii/使用递归的方法1、遍历根节点开始的路径2、遍历根节点左子节点的路径数量3、遍历根节点右子节点的路径数量4、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * ...

2020-03-30 22:14:39 155

原创 【leetcode每日刷题】113. Path Sum II

https://leetcode.com/problems/path-sum-ii/使用回溯法。package leetcode;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;class TreeNode { int val; TreeNode left...

2020-03-29 17:01:42 217

原创 【leetcode每日刷题】112. Path Sum

https://leetcode.com/problems/path-sum/package leetcode;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}public class num112{ public bool...

2020-03-29 16:39:43 141

原创 【leetcode每日刷题】435. Non-overlapping Intervals

https://leetcode.com/problems/non-overlapping-intervals/贪婪算法import java.util.Arrays;import java.util.Comparator;class Solution { public int eraseOverlapIntervals(int[][] intervals) { ...

2020-03-29 16:16:52 211

原创 【leetcode每日刷题】46. Permutations

https://leetcode.com/problems/permutations/对于数组进行全排列,使用回溯法或者深度遍历的方法。1、回溯法使用temp list表示当前排列的数组,回溯法对temp list的大小进行判断,如果和nums的大小一致,加入到结果列表中。回溯法对新加入的元素按位插入。package leetcode;import java.util.Arra...

2020-03-29 13:23:17 182

原创 【leetcode每日刷题】368. Largest Divisible Subset

https://leetcode.com/problems/largest-divisible-subset/import java.util.ArrayList;import java.util.Arrays;import java.util.List;class Solution { public List<Integer> largestDivisibleS...

2020-03-24 12:59:19 186

原创 【leetcode每日刷题】81. Search in Rotated Sorted Array II

https://leetcode.com/problems/search-in-rotated-sorted-array-ii/使用二分查找的方法,相比33题思路相同,但是有重复数字的判断class Solution { public boolean search(int[] nums, int target) { int start = 0; i...

2020-03-23 12:13:17 137

原创 【leetcode每日刷题】480. Sliding Window Median

https://leetcode.com/problems/sliding-window-median/使用最小堆+最大堆的方法实现,中位数实现的一种方法。import java.util.Collection;import java.util.Collections;import java.util.PriorityQueue;class Solution { publ...

2020-03-22 20:54:00 198

原创 【leetcode每日刷题】4. Median of Two Sorted Arrays

https://leetcode.com/problems/median-of-two-sorted-arrays/class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int len1 = nums1.length; int len2 ...

2020-03-22 17:37:43 154

原创 【leetcode每日刷题】295. Find Median from Data Stream

https://leetcode.com/problems/find-median-from-data-stream/使用两个堆,small采用最大堆存储左半边较小的数,large采用最小堆存储右半边较大的数。每次是small堆的值个数和large中的相等或者多一个,small中的最大值始终小于large中的最小值。import java.util.PriorityQueue;impo...

2020-03-22 16:53:13 149

原创 【leetcode每日刷题】137. Single Number II

https://leetcode.com/problems/single-number-ii/Given anon-emptyarray of integers, every element appearsthreetimes except for one, which appears exactly once. Find that single one.Note:Your a...

2020-03-22 16:29:00 195

原创 【leetcode每日刷题】210. Course Schedule II

https://leetcode.com/problems/course-schedule-ii/import java.util.LinkedList;class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { int[][] matrix = new int[...

2020-03-22 15:28:09 151

原创 【leetcode每日刷题】215. Kth Largest Element in an Array

找第k大的数1、使用最小堆,当大于k的时候并且插入的值大于堆顶元素的时候,删除堆顶元素,在把新元素加入堆中。public int heap(int[] nums, int k) { PriorityQueue<Integer> heap = new PriorityQueue<>(); for(int num:nums){ ...

2020-03-22 14:09:39 183

原创 【leetcode每日刷题】200. Number of Islands

https://leetcode.com/problems/number-of-islands/class Solution { public int numIslands(char[][] grid) { int m = grid.length; if(m == 0) return 0; int n = grid[0].leng...

2020-03-18 21:59:36 116

原创 【leetcode刷题】315. Count of Smaller Numbers After Self

https://leetcode.com/problems/count-of-smaller-numbers-after-self/使用归并排序的方法。记录数组的索引、创建索引数组,对索引数组进行归并排序合并的时候分为:left列表和right列表当right列表中的数字比较小,则从right列表中复制一个数字到新数组中,则表明有小数字前移了,则rightcount++当left列...

2020-03-18 15:01:55 153

原创 【leetcode每日刷题】392. Is Subsequence

https://leetcode.com/problems/is-subsequence/index记录t中已经遍历的位置。class Solution { public boolean isSubsequence(String s, String t) { int index = -1; for(char c:s.toCharArray()){...

2020-03-15 14:02:09 114

原创 【leetcode每日刷题】264. Ugly Number II

https://leetcode.com/problems/ugly-number-ii/submissions/一、设置可以乘2,3,5的index,避免重复二、每个index乘2,3,5之后选取最小的一个放在结果队列中。三、更新indexclass num264 { public int nthUglyNumber(int n) { int index...

2020-03-15 13:06:53 110

原创 【leetcode每日刷题】263. Ugly Number

https://leetcode.com/problems/ugly-number/如果除2,3,5后还是有余数,说明不是丑数class Solution { public boolean isUgly(int num) { int[] items = {2, 3, 5}; for(int item:items){ whil...

2020-03-15 12:33:48 118

原创 【leetcode每日刷题】260. Single Number III

https://leetcode.com/problems/single-number-iii/Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements ...

2020-03-15 12:22:56 131

原创 matchzoo中文适配笔记

中文适配需要参考源代码,同时修改源码,可以分两种情况使用1、下载源码修改然后当项目运行,2、pip install matchzoo 参考源码把中文需要改的地方都重新实现一遍,代码中调用matchzoo使用。一、修改源代码参考tutorials中的init1、首先修改获取数据的文件,添加文件matchzoo/datasets/chinese_qa/load_data.py"""Wiki...

2020-03-05 09:22:35 1616 2

原创 【leetcode刷题】115. Distinct Subsequences

https://leetcode.com/problems/distinct-subsequences/class Solution { public int numDistinct(String s, String t) { int ls = s.length(); int lt = t.length(); int[][] dp = ...

2020-03-02 16:02:25 125

原创 【DP】将一个数组分为两个数组,使两个数组和的差最小

/*将一个数组分为两个数组,使两个数组和的差最小*/public class SplitArray{ public int diff(int[] array){ int sum = 0; for(int i=0; i<array.length; i++){ sum += array[i]; } ...

2020-03-02 14:15:18 2053 1

原创 【leetcode每日刷题】97. Interleaving String

Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.Example 1:Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"Output: trueExample 2:Input: s1 = "aabcc", s2 = "...

2020-02-26 22:55:34 134

原创 【leetcode每日刷题】83. Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear onlyonce.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1-...

2020-02-26 22:31:59 112

原创 【leetcode每日刷题】82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1-&gt...

2020-02-26 22:25:00 94

原创 【leetcode每日刷题】61. Rotate List

Given a linkedlist, rotate the list to the right bykplaces, wherekis non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplan...

2020-02-26 17:40:30 136

原创 【leetcode每日刷题】445. Add Two Numbers II

You are given twonon-emptylinked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return i...

2020-02-26 17:10:25 132

原创 【leetcode每日刷题】146. LRU Cache

Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following operations:getandput.get(key)- Get the value (will always be positive) of the key if th...

2020-02-26 16:06:40 210

原创 【leetcode每日刷题】354. Russian Doll Envelopes

You have a number of envelopes with widths and heights given as a pair of integers(w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than th...

2020-02-24 15:40:22 126

原创 【leetcode每日刷题】221. Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.Example:Input: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4class nu...

2020-02-23 22:28:27 281

原创 【leetcode刷题】120. Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...

2020-02-23 21:31:05 138

原创 【leetcode刷题】145. Binary Tree Postorder Traversal

Given a binary tree, return thepostordertraversal of its nodes' values.Example:Input:[1,null,2,3] 1 \ 2 / 3Output:[3,2,1]Follow up:Recursive solution is trivial, coul...

2020-02-21 23:50:10 170

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除