摘要: 关于java中数组的排序问题 1.ArrayList自带函数 2.Arrays.sort+自定义排序方法 package Method; /* * java中数组排序问题 * * */ import java.util.ArrayList; import java.util.Arrays; impo 阅读全文
posted @ 2021-04-19 16:34 withwind777 阅读(337) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode-cn.com/problems/string-to-integer-atoi/ 截取字符然后乘10操作即可,坑点在于溢出判断,可以用MAX_INT/10与该数比较。 自己写的代码比较蠢,有漏洞,但数据可能比较水所以过了。官方题解是自动机,学会了再来写。。 阅读全文
posted @ 2021-02-22 19:51 withwind777 阅读(43) 评论(0) 推荐(0)
摘要: 链接 https://leetcode-cn.com/problems/fair-candy-swap/ 思路:假设从A中拿出y给B,从B中拿出x给A,则sumA+x-y=sumB-x+y, 即y=(sumA-sumB)/2+x public int[] fairCandySwap(int[] A, 阅读全文
posted @ 2021-02-02 10:44 withwind777 阅读(60) 评论(0) 推荐(0)
摘要: 链接 https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 思路一:双指针+HashSet 官方题解 class Solution { public int lengthOfLongestSu 阅读全文
posted @ 2021-02-02 10:20 withwind777 阅读(47) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode-cn.com/problems/find-pivot-index/ 一开始自己想到的思路是前缀和后缀和然后求相等值的位置,看了题解发现是自己笨比了。nums[i]前面的元素和*2+nums[i]=元素总和 的i即为所求。另外个人觉得一个坑点在于默认没有元素 阅读全文
posted @ 2021-01-28 10:19 withwind777 阅读(50) 评论(0) 推荐(0)
摘要: 链接 https://leetcode-cn.com/problems/number-of-equivalent-domino-pairs/ 代码如下 public class Problem1128 { public int numEquivDominoPairs(int[][] dominoes 阅读全文
posted @ 2021-01-26 10:16 withwind777 阅读(55) 评论(0) 推荐(0)
摘要: 链接: https://leetcode-cn.com/problems/regions-cut-by-slashes/ 代码如下。 package Leetcode; import java.util.HashSet; import java.util.Set; public class Prob 阅读全文
posted @ 2021-01-26 09:59 withwind777 阅读(81) 评论(0) 推荐(0)
摘要: 链接: https://leetcode-cn.com/problems/add-two-numbers/ 题目描述: 给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可 阅读全文
posted @ 2021-01-24 20:18 withwind777 阅读(60) 评论(0) 推荐(0)
摘要: 链接: https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected/ 题目描述: 用以太网线缆将 n 台计算机连接成一个网络,计算机的编号从 0 到 n-1。线缆用 connections 表示,其中 阅读全文
posted @ 2021-01-23 21:22 withwind777 阅读(72) 评论(0) 推荐(0)
摘要: 题目链接: https://leetcode-cn.com/problems/add-to-array-form-of-integer/ 题目概述: 对于非负整数 X 而言,X 的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果 X = 1231,那么其数组形式为 [1,2,3,1]。 给定 阅读全文
posted @ 2021-01-22 16:12 withwind777 阅读(72) 评论(0) 推荐(0)