![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 85
JYY_JYY_
这个作者很懒,什么都没留下…
展开
-
Leetcode笔记——回溯
1.括号生成2. 组合总和1. 括号生成输入:n = 3输出:[ "((()))", "(()())", "(())()", "()(())", "()()()" ]---------------------------------------------------------class Solution { List<String> list; public List..原创 2020-10-30 09:08:50 · 59 阅读 · 0 评论 -
Leetcode笔记——栈和队列
栈:1. 栈的压入、弹出序列2.用两个栈实现队列1. 栈的压入、弹出序列class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { Stack<Integer> stack = new Stack<>(); int i = 0; for(int num: pushed){ ..原创 2020-10-28 11:33:08 · 80 阅读 · 0 评论 -
LeetCode刷题,java知识点
python转了java,记录一些刷题的知识点。1.Stackimport java.util.Stack;Stack<Integer> stack = new Stack<Integer>();出栈并返回栈顶元素:stack.pop();入栈:stack.push(int a);更常用 stack.add(int a);查看...原创 2020-04-10 00:47:14 · 487 阅读 · 1 评论 -
LeetCode 记忆题模板(快排,非递归遍历...)
中序遍历class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> ans = new ArrayList<>(); Stack<TreeNode> stack = new Stack<>(); TreeNode cur = root; while(cur !=原创 2020-09-02 00:05:38 · 117 阅读 · 0 评论 -
Leetcode笔记——数组
数组:1.和为s的连续正数序列2.只出现一次的数字3.丑数,质数因子排序1.和为s的连续正数序列输入:target = 9输出:[[2,3,4],[4,5]]-------------------------------------譬如说如果有两个连续的数之和等于target,那么相差为1, (target - 1) % 2 == 0, 且数组一定是从 (target - 1) / 2开始的,数组的元素就是2个;如果是3个连续的数组,那么三个数之间相差为1、2,(targe..原创 2020-10-24 04:35:45 · 128 阅读 · 0 评论 -
Leetcode笔记——链表
链表:1.反转链表2.合并有序链表1.反转链表public ListNode reverseList(ListNode head) { if(head == null) return null; ListNode p = null; ListNode q = head; ListNode r; while( q!= null){ r = q.next; .原创 2020-10-24 04:29:42 · 50 阅读 · 0 评论 -
Leetcode笔记——树
树:1.二叉搜索树的第k大节点2. 公共祖先二叉树的公共祖先 二叉搜索树的公共祖先3. 翻转二叉树4.合并二叉树1. 二叉搜索树的第k大节点class Solution { int ans = 0; int find = -999; public int kthLargest(TreeNode root, int k) { dfs(root, k); return find; } public...原创 2020-10-24 04:28:42 · 73 阅读 · 0 评论 -
Leetcode笔记——二进制
1.汉明距离1.汉明距离class Solution { public int hammingDistance(int x, int y) { int temp = x^y; System.out.println(temp); int sum =0; while(temp != 0){ if((temp & 1) == 1){ sum++; ...原创 2020-10-24 04:14:46 · 63 阅读 · 0 评论 -
Leetcode笔记——贪心+DP
1. 跳跃游戏2.视频拼接1. 跳跃游戏输入: [2,3,1,1,4]输出: true解释: 我们可以先跳 1 步,从位置 0 到达 位置 1, 然后再从位置 1 跳 3 步到达最后一个位置。--------------------------------------------------------------------------------思路:遍历数组,维护一个max表示目前最远能跳到的位置class Solution { public boolean ca..原创 2020-10-24 04:02:05 · 61 阅读 · 0 评论 -
leetcode常见题记录
1.反转链表public ListNode reverseList(ListNode head) { if(head == null) return null; ListNode p = null; ListNode q = head; ListNode r; while( q!= null){ r = q.next; q.next = p; p原创 2020-10-20 02:56:36 · 112 阅读 · 0 评论 -
LeetCode 二分法细节,踩坑记录
1.传统二分,在排序数组中找某个数:[0,nums.length] 左右都闭区间int left = 0;int right = nums.length - 1;while(left <= right){ int mid = left + (right - left)/2; if(nums[mid] > target) right = mid - 1;...原创 2020-04-15 05:05:05 · 215 阅读 · 1 评论