![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计
三岁就很萌@D
这个作者很懒,什么都没留下…
展开
-
LeetCode - 919. 完全二叉树插入器 (数组)
无原创 2022-06-04 20:24:53 · 79 阅读 · 0 评论 -
LeetCode - 900. RLE 迭代器
无原创 2022-06-03 15:52:25 · 98 阅读 · 0 评论 -
LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
List + 小顶堆 + 栈(双端队列实现的栈)import java.util.*;class DinnerPlates { //list 栈 双端队列 //存放所有未满栈的下标的队列 private PriorityQueue<Integer> deque; //按顺序存放所有栈 private List<Deque<Integer>> list; //栈容量 private int cap...原创 2022-05-31 12:54:34 · 571 阅读 · 0 评论 -
LeetCode - 715. Range 模块(TreeSet) *****
TreeSetclass RangeModule { class Pair{ int left; int right; public Pair(int left,int right){ this.left = left; this.right = right; } } class PairComparator implements Comparator&l..原创 2022-05-30 21:11:12 · 162 阅读 · 0 评论 -
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
class MedianFinder { /** initialize your data structure here. */ private PriorityQueue<Integer> minHeap;//小顶堆 private PriorityQueue<Integer> maxHeap;//大顶堆 public MedianFinder() { minHeap = new PriorityQueue<Integer..原创 2022-05-29 17:29:50 · 116 阅读 · 0 评论 -
LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
哈希表+优先队列class FreqStack { class Node{ //值的大小 int val; //值出现的频率 int freq; //值出现的时间 时间越大越靠近栈顶 int t; public Node(int val,int freq,int t){ this.val = val; this.freq = freq..原创 2022-05-28 21:00:45 · 114 阅读 · 0 评论 -
LeetCode - 933 最近的请求次数
双端队列class RecentCounter { private Deque<Integer> deque; public RecentCounter() { deque = new LinkedList<>(); } public int ping(int t) { deque.offerLast(t); while(deque.size()!= 0 && t - 3..原创 2022-05-28 17:28:07 · 52 阅读 · 0 评论 -
LeetCode - 706 设计哈希映射(设计) *
超大数组class MyHashMap { private int[] map ; public MyHashMap() { map = new int[1000001]; Arrays.fill(map,-1); } public void put(int key, int value) { map[key] = value; } public int get(int key) { ..原创 2022-05-28 16:37:53 · 73 阅读 · 0 评论 -
LeetCode - 703 数据流中的第 K 大元素(设计 - 优先队列)
优先队列class KthLargest { private PriorityQueue<Integer> queue; private int k; public KthLargest(int k, int[] nums) { queue = new PriorityQueue<Integer>(); this.k = k; for(int num : nums){ if(que..原创 2022-05-28 11:30:46 · 45 阅读 · 0 评论 -
LeetCode - 707 设计链表 (设计)
单链表注意 第一次添加节点 或者 addAtIndex(添加的节点在末尾)deleteAtIndex(删除了末尾的节点) 都有可能造成尾指针的变动 要进行判断并且更新尾指针class MyLinkedList { class Node{ int val;//节点的值 Node next;//节点的next指针 public Node(int val){ this.val = val; } }..原创 2022-05-28 11:12:57 · 56 阅读 · 0 评论 -
LeetCode - 677 键值映射(设计)*
前缀树+哈希表class MapSum { class TrieNode{ int val = 0; TrieNode[] child = new TrieNode[26]; } private TrieNode root; private Map<String,Integer> map; public MapSum() { root = new TrieNode(); map ..原创 2022-05-28 09:46:51 · 59 阅读 · 0 评论 -
LeetCode - 380 O(1) 时间插入、删除和获取随机元素 (设计 哈希表+数组)
哈希表+listclass RandomizedSet { //将值放入list中 为了可以随机取数 private List<Integer> list; //map的key是值 map的val是 值在list中的位置 //为了方便在o(1)时间内 插入删除值 private Map<Integer,Integer> map; public RandomizedSet() { list = new Array..原创 2022-05-25 19:48:16 · 82 阅读 · 0 评论 -
LeetCode - 303 区域和检索 - 数组不可变 (设计 前缀和数组)
class NumArray { private int[] preSum; public NumArray(int[] nums) { int n = nums.length; preSum = new int[n+1]; for(int i = 0; i < n;i++) preSum[i+1] = preSum[i] + nums[i]; } public int sumRange(int...原创 2022-05-25 19:04:36 · 58 阅读 · 0 评论 -
LeetCode - 232 用栈实现队列 (设计 双栈实现队列)
用两个栈实现队列class MyQueue { //使用两个栈实现队列 //主栈 private Deque<Integer> deque1; //辅助栈 private Deque<Integer> deque2; public MyQueue() { deque1 = new LinkedList<>(); deque2 = new LinkedList<>();..原创 2022-05-25 09:37:31 · 79 阅读 · 0 评论 -
LeetCode - 225 用队列实现栈
使用两个队列class MyStack { //使用两个队列实现栈 //主队列 private Deque<Integer> deque1; //辅助队列 private Deque<Integer> deque2; public MyStack() { deque1 = new LinkedList<>(); deque2 = new LinkedList<>();..原创 2022-05-25 09:34:08 · 76 阅读 · 0 评论 -
LeetCode - 379 电话目录管理系统(设计)
双端队列class PhoneDirectory { private Deque<Integer> deque; public PhoneDirectory(int maxNumbers) { deque = new LinkedList<>(); for(int i = 0; i < maxNumbers;i++) deque.offerLast(i); } publ...原创 2022-05-24 19:23:19 · 116 阅读 · 0 评论 -
LeetCode - 362 敲击计数器(设计)
双端队列class HitCounter { private Deque<Integer> deque; public HitCounter() { deque = new LinkedList<>(); } public void hit(int timestamp) { deque.offerLast(timestamp); } public int getHits(i..原创 2022-05-24 19:13:24 · 136 阅读 · 0 评论 -
LeetCode - 359 日志速率限制器 (设计)
哈希表class Logger { //printMap记录了字符串最后被打印的时间 private Map<String,Integer> printMap; public Logger() { printMap = new HashMap<>(); } public boolean shouldPrintMessage(int timestamp, String message) { if(..原创 2022-05-24 16:54:22 · 178 阅读 · 0 评论 -
LeetCode - 348 设计井字棋 (设计)
class TicTacToe { private int[][] rows; private int[][] cols; private int[][] diags; private int n; public TicTacToe(int n) { //rows记录每个用户每行有多少棋子 rows = new int[3][n]; //cols记录每个用户每列有多少棋子 cols = new i...原创 2022-05-24 11:04:21 · 133 阅读 · 0 评论 -
LeetCode - 346. 数据流中的移动平均值(设计)
class MovingAverage { private Deque<Integer> deque; private int size; int total; public MovingAverage(int size) { this.deque = new LinkedList<>(); this.size = size; total = 0; } public d..原创 2022-05-24 10:08:15 · 72 阅读 · 0 评论 -
LeetCode - 288 单词的唯一缩写(设计)
class ValidWordAbbr { //存放单词缩写 对应的单词 Map<String, List<String>> map = new HashMap<>(); public ValidWordAbbr(String[] dictionary) { for(String word : dictionary){ String abbreviation = calabbreviation(wo...原创 2022-05-24 09:40:07 · 79 阅读 · 0 评论 -
LeetCode - 281 锯齿迭代器 (设计)
双指针import java.util.NoSuchElementException;public class ZigzagIterator { private List<Integer> pv1; private List<Integer> pv2; private int pos1 ; private int pos2 ; private int num ; public ZigzagIterator(List<I...原创 2022-05-24 08:37:48 · 185 阅读 · 0 评论 -
LeetCode - 251展开二维向量(设计 迭代器 双指针)*
class Vector2D { List<Integer> list = new ArrayList<>();//将二维向量存放到一维数组中 int pos = 0; public Vector2D(int[][] vec) { for(int[] v: vec){ for(int n : v){ list.add(n); } } }...原创 2022-05-23 09:53:29 · 171 阅读 · 0 评论