数组leetcode-java leetcode两个

leetcode-1732-easy

Find the Highest Altitude 思路一:直接遍历 public int largestAltitude(int[] gain) { int val = 0; int max = val; for (int i : gain) { val += i; max = Math.max( ......
leetcode 1732 easy

leetcode-1646-easy

Get Maximum in Generated Array You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way: nums[0] = ......
leetcode 1646 easy

leetcode-2169-easy

Count Operations to Obtain Zero You are given two non-negative integers num1 and num2. In one operation, if num1 >= num2, you must subtract num2 from ......
leetcode 2169 easy

leetcode-2180-easy

Count Integers With Even Digit Sum Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are ......
leetcode 2180 easy

leetcode-1455-easy

Check If a Word Occurs As a Prefix of Any Word in a Sentence Given a sentence that consists of some words separated by a single space, and a searchWor ......
leetcode 1455 easy

leetcode-1464-easy

Maximum Product of Two Elements in an Array Given the array of integers nums, you will choose two different indices i and j of that array. Return the ......
leetcode 1464 easy

leetcode-1512-easy

Number of Good Pairs Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j. E ......
leetcode 1512 easy

leetcode-1550-easy

Three Consecutive Odds Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. Examp ......
leetcode 1550 easy

leetcode-1572-easy

Matrix Diagonal Sum Given a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagona ......
leetcode 1572 easy

[LeetCode] 1688. Count of Matches in Tournament

You are given an integer n, the number of teams in a tournament that has strange rules: If the current number of teams is even, each team gets paired ......
Tournament LeetCode Matches Count 1688

Leetcode 80. 删除有序数组中的重复项 II

被前面类似的题禁锢了思路,自己写的双指针,感觉题解很巧妙,记录一下。这个解法不用记录cnt。 通用解法 为了让解法更具有一般性,我们将原问题的「保留 2 位」修改为「保留 k 位」。 对于此类问题,我们应该进行如下考虑: 由于是保留 k 个相同数字,对于前 k 个数字,我们可以直接保留 对于后面的任 ......
数组 Leetcode 80 II

Leetcode刷题day6-哈希表.双指针.三~四数求和.

454.四数相加Ⅱ 454. 四数相加 II - 力扣(LeetCode) 给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n ,请你计算有多少个元组 (i, j, k, l) 能满足: 0 <= i, j, k, l < n nums1[i] + nums2[ ......
指针 Leetcode day6 day

稀疏数组 待完善

package array; import java.util.Arrays; public class ArrayDemo08 { public static void main(String[] args) { //1.创建一个二维数组 11*11 0:没有棋子 1;黑棋 2:白棋 int[][ ......
数组

[LeetCode Hot 100] LeetCode19. 删除链表的倒数第N个结点

题目描述 思路一:采用两次遍历 第一遍遍历先获取链表的长度length 第二次从dummy节点开始走length - n步 然后将该节点指向下下个节点 思路二:采用一次遍历 设置虚拟节点dummyHead指向head 设定双指针p和q,初始都指向虚拟节点dummyHead 移动q,直到p与q之间相隔 ......
LeetCode 结点 Hot 100 19

[LeetCode Hot 100] LeetCode21. 合并两个有序链表

题目描述 思路:新建dummy去"穿针引线" 新建一个dummy节点去"穿针引线" 注意最后返回的是dummy.next 方法一: /** * Definition for singly-linked list. * public class ListNode { * int val; * List ......
LeetCode 两个 Hot 100 21

代码随想训练营第五十六天(Python)| 583. 两个字符串的删除操作、72. 编辑距离

583. 两个字符串的删除操作 class Solution: def minDistance(self, word1: str, word2: str) -> int: n, m = len(word1), len(word2) # dp 数组代表使得 word1 以 i-1 结尾和 word2 ......
训练营 字符串 随想 字符 两个

秦疆的Java课程笔记:57 数组 Arrays类讲解

数组的工具类java.util.Arrays 由于数组对象本身并没有什么方法可以供我们使用,但API中提供了一个工具类Arrays供我们使用,从而可以对数据对象进行一些基本操作。 查看JDK帮助文档-Class Arrays Arrays类中的方法都是static修饰的静态方法,在使用的时候可以直接 ......
数组 课程 笔记 Arrays Java

秦疆的Java课程笔记:59 数组 稀疏数组

当一个数组中大部分元素都是0,或者为同一值的数组时,可以使用稀疏数组来保存该数组。 稀疏数组的处理方式是: 记录数组一共有几行几列,有多少个不同值 把具有不同值的元素和行列及值记录在一个小规模的数组中,从而缩小程序的规模 public class ArrayDemo1 { public static ......
数组 课程 笔记 Java

秦疆的Java课程笔记:58 数组 冒泡排序

总共有八大排序,其中冒泡排序无疑是较为出名的排序算法之一。 冒泡排序的代码相当简单,两层循环,外层冒泡轮数,里层依次比较。 当看到嵌套循环,应该立马意识到,这个算法的时间复杂度是\(O(n^2)\)。 冒泡排序基本步骤: 比较数组中两个相邻元素,如果第一个数比第二个数大,就交换位置。 每一次比较,产 ......
数组 课程 笔记 Java

秦疆的Java课程笔记:56 数组 二维数组

多维数组可以看成是数组的数组,比如二维数组就是一个特殊的一维数组,其每一个元素都是一个一维数组。 秦疆老师表示Java中并不太使用二维以上的多维数组。 例如二维数组:int a[][] = new int[2][5],就可以看成是一个两行五列的数组 public class ArrayDemo1 { ......
数组 课程 笔记 Java

刷题复习(二)数组-双指针

刷题复习(二)数组-双指针 https://labuladong.gitee.io/algo/di-ling-zh-bfe1b/shuang-zhi-fa4bd/ 1、删除有序数组中的重复项 慢指针用于统计不重复项,快指针用于不停前进对比是否有新的不重复项,有的话进行替换 class Solutio ......
数组 指针

shell脚本-两个list查找匹配项

#!/bin/bash search_list='xx/search_list.txt' list='xx/revise_list.txt' result='xx/result.txt' # 逐行读取list文件 while IFS= read -r line; do # 在search_list文 ......
脚本 两个 shell list

[LeetCode Hot 100] LeetCode234. 回文链表

题目描述 思路1:将值复制到数组中然后使用双指针 计算链表的长度 创建等长的数组 将链表中的数依次放入数组中 使用左右指针判断链表是否是回文链表 时间复杂度:O(n) 空间复杂度:O(n) 思路2:快慢指针+反转链表 用快慢指针,快指针走两步,慢指针走一步,快指针遇到终止位置时,慢指针就在链表中间位 ......
LeetCode 回文 Hot 100 234

[LeetCode Hot 100] LeetCode206. 反转链表

题目描述 思路:双指针算法 方法一: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) ......
LeetCode Hot 100 206

[LeetCode Hot 100] LeetCode49. 字母异位词

题目描述 思路:哈希表 对字符串排序,如果是异位词,排序后就变成一样的了。 方法一: class Solution { public List<List<String>> groupAnagrams(String[] strs) { Map<String, List<String>> map = n ......
LeetCode 字母 Hot 100 49

[LeetCode Hot 100] LeetCode141. 环形链表

题目描述 思路:快慢指针 slow指针:每次移动一个节点 fast指针:每次移动两个节点 如果链表中存在环,fast指针最终会在某一时刻追上slow指针,这是由于移动速度快的fast指针会在某个时刻绕圈并追上速度慢的slow指针 条件 fast != null && fast.next != nul ......
LeetCode 环形 Hot 100 141

Java 21中的两个值得关注的Bug修复

在Java 21中,除了推出很多新特性之外,一些Bug修复,也需要注意一下。因为这些改变可能在升级的时候,造成影响。 Double.toString()和Float.toString()的精度问题修复 比如:对于Double.String(1e23): 在Java 19后,输出内容为:1.0E23 ......
两个 Java Bug

[LeetCode] 2264. Largest 3-Same-Digit Number in String

You are given a string num representing a large integer. An integer is good if it meets the following conditions: It is a substring of num with length ......
Same-Digit LeetCode Largest Number String

LeetCode-Java:55.跳跃游戏

题目 给你一个非负整数数组 nums ,你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个下标,如果可以,返回 true ;否则,返回 false 。 示例 1: 输入:nums = [2,3,1,1,4] 输出:true 解释:可以先跳 ......
LeetCode-Java LeetCode Java 55

面试leetcode算法经典 150 题

数组、字符串 1.合并两个有序数组 给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2,另有两个整数 m 和 n ,分别表示 nums1 和 nums2 中的元素数目。 请你 合并 nums2 到 nums1 中,使合并后的数组同样按 非递减顺序 排列。 注意:最终,合并后数组不应由 ......
算法 leetcode 经典 150