![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
力扣
小暖壶的盖
这个作者很懒,什么都没留下…
展开
-
leetcode-合并二叉树、翻转二叉树、计算二叉树的深度
使用深度优先搜索,把每个节点都看作根节点,做三件事,val值加起来,合并左子树,合并右子树。递归调用。这里发现val值和null值可以直接加,TreeNode(root1.val+root2.val);/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} *原创 2021-04-14 16:10:03 · 62 阅读 · 0 评论 -
leetcode(异或)-数组异或操作、汉明距离、只出现一次的数字
主要是知道异或操作符是 ^ ,就好class Solution { public int xorOperation(int n, int start) { int[] nums = new int[n]; int result = 0; for(int i = 0; i<n; i++){ nums[i]=start + 2*i; result = result ^ nums[i];原创 2021-04-11 16:49:34 · 54 阅读 · 0 评论 -
leetcode-删除链表中的结点、反转链表
请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点。传入函数的唯一参数为 要被删除的节点 。因为我们无法访问要被删除节点的前一个节点,所以只能用后一个节点的内容去覆盖要被删除的节点。然后删除后一个节点(后一个节点由于它的地址已经不在前一个节点中有储存了,所以无法访问,也就相当于删除了。)class Solution { public void deleteNode(ListNode node) { node.val=node.next.val; node.原创 2021-04-11 16:36:52 · 69 阅读 · 0 评论 -
leetcode-统计匹配检索规则的物品数量
|原创 2021-04-09 17:17:13 · 89 阅读 · 0 评论 -
leetcode-重新排列数组、整数反转、回文数
class Solution { public int[] shuffle(int[] nums, int n) { int[] shuffle = new int[n*2]; for(int i = 0; i<n; i++){ shuffle[i*2] = nums[i]; shuffle[i*2+1] = nums[i+n]; } return shuffle; }}这里要注意shuffl原创 2021-04-02 16:50:04 · 111 阅读 · 0 评论 -
leetcode-415-字符串相加
415. 字符串相加class Solution { public String addStrings(String num1, String num2) { //从最末位开始加,因此指针i,j先指向字符串最后一位 //add代表是否有进位 int i = num1.length() - 1, j = num2.length() - 1, add = 0; //StringBuffer类对字符串进行操作 StringBuffer转载 2020-08-14 20:57:59 · 130 阅读 · 0 评论 -
leetcode-删除链表节点,设计停车系统,宝石与石头
删除链表节点:class Solution { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; }}1603.设计停车系统class ParkingSystem { int big,medium,small; public ParkingSystem(int big, int medium,原创 2021-03-28 21:45:50 · 50 阅读 · 0 评论 -
leetcode-两数之和、一维数组的动态和、好数对的数目
1.暴力法class Solution { public static int[] twoSum(int[] nums, int target) { int[] index = new int[2]; for(int i=0; i<nums.length; i++){ for(int j=i+1; j<nums.length; j++){ if (target == nums[i]+num原创 2021-03-31 21:51:38 · 52 阅读 · 0 评论 -
leetcode-DFS
转载来自:https://www.bilibili.com/video/BV1qE411E7di?from=search&seid=13624967053223072523dfs三个重要的点:截止条件遍历候选节点对候选节点的筛选例题一:输入: p = ‘A’,‘B’,‘C’输出:ABC ACB BAC BCA CAB CBA截止条件:level==p.length()+1遍历候选节点:for(var i=0; i<p.length; i++)筛选候选节点:pb=【fa原创 2021-03-31 21:49:02 · 51 阅读 · 0 评论 -
leetcode-20-有效的括号
Java toCharArray() 方法:将字符串转换为字符数组public class Test { public static void main(String args[]) { String Str = new String("www.runoob.com"); System.out.print("返回值 :" ); System.out.println( Str.toCharArray() ); }}输出为:返回值 :ww转载 2020-08-20 16:13:07 · 76 阅读 · 0 评论