摘要:
题目链接:https://leetcode-cn.com/problems/single-number/submissions/ 要求O(1)的空间复杂度,不用排序。 动画演示: class Solution { //位运算(异或) public int singleNumber(int[] num 阅读全文
摘要:
class Solution { //全排列问题 Set<List<Character>> res = new HashSet<>(); public String[] permutation(String s) { char []strs = s.toCharArray(); int len = 阅读全文
摘要:
class Solution { public int lastRemaining(int n, int m) { //模拟法超时 int pos = 0;//长度为1时候安全的下标 //反推的过程 //从i-1个人到i人的安全序号的变化 //正过程: //1、下标为j+1的成为数组头,j前面的人加 阅读全文
摘要:
解题:前序遍历加上筛选 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = 阅读全文
摘要:
平衡树:对于每一个节点它的左右子树深度差不能超过1 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode( 阅读全文
摘要:
二叉搜索树:左子树的值小于右子树的值(不会出现重复的情况) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN 阅读全文