伴你如风、护你如影|

xzh-yyds

园龄:3年8个月粉丝:0关注:2

leetcode394-字符串解码
摘要: 字符串解码 递归 class Solution { public String decodeString(String s) { StringBuilder sb = new StringBuilder(); int i = 0, n = s.length(); while(i < n){ if(s
16
0
0
leetcode706-设计哈希映射
摘要: 设计哈希映射 哈希+链表 class MyHashMap { class Pair{ int key; int value; public Pair(int key, int value){ this.key = key; this.value = value; } } LinkedList arr
16
0
0
leetcode143-重排链表
摘要: 重排链表 快慢指针+翻转链表 通过快慢指针找到中间节点,然后将后半段进行翻转,然后与前半段进行拼接。 class Solution { public void reorderList(ListNode head) { if(head == null || head.next == null) ret
19
0
0
leetcode440-字典序的第K小数字
摘要: 字典序的第K小数字 字典树 对于给定的最大数n和剩余数字k,维护一个当前的字典树前缀cur,先让k减去最小的数字1,然后计算以cur为开头的字典树的容量。计算得出的字典树的容量大于k,说明k无法容纳整棵字典树,那么就仅仅取一个数(即cur10),更新cur = cur10,缩小字典树的范围,继续以c
13
0
0
leetcode226-翻转二叉树
摘要: 翻转二叉树 递归 class Solution { public TreeNode invertTree(TreeNode root) { if(root == null) return root; TreeNode l = invertTree(root.left), r = invertTree
50
0
0
leetcode225-用队列实现栈
摘要: 用队列实现栈 class MyStack { LinkedList<Integer> list = new LinkedList<>(); public MyStack() { } public void push(int x) { list.add(x); } public int pop() {
13
0
0
leetcode223-矩形面积
摘要: 矩形面积 计算重叠面积 重叠面积计算方法如下:重叠部分如果有的话肯定是一个矩形,这个矩形的左边界是两个矩形的左边界取较大值,右边界是两个矩形的右边界取较小值。上下边界同理。这样可以计算出重叠部分的面积,返回结果为总面积减去重叠部分面积即可。 class Solution { public int c
24
0
0
leetcode222-完全二叉树的节点个数
摘要: 完全二叉树的节点个数 递归 class Solution { public int countNodes(TreeNode root) { if(root == null) return 0; return countNodes(root.left)+countNodes(root.right)+1
26
0
0
leetcode97-交错字符串
摘要: 交错字符串 dp 定义一个二维的dp数组,表示s1选取 i 个字符和s2选取 j 个字符组成s3的前 i+j 个字符能否成立。 dp递归方程: 如果i == 0 && j == 0,表示没有任何字符,true 如果i == 0,那么dp[i][j] = dp[i][j-1] && s2.charAt
28
0
0
leetcode80-删除有序数组中的重复项 II
摘要: 删除有序数组中的重复项 II class Solution { public int removeDuplicates(int[] nums) { int cnt = 0, index = 0; for(int i = 0; i < nums.length; i++){ if(i == 0){ cn
15
0
0
点击右上角即可分享
微信分享提示
深色
回顶
展开