leetcode greatest divisor common

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

[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

[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

[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

[LeetCode Hot 100] LeetCode3. 无重复字符的最长子串

题目描述 思路:滑动窗口 定义需要维护的变量 // 1. 定义需要维护的变量 int max_len = 0; Map<Character, Integer> hashmap = new HashMap<>(); 窗口不满足条件,窗口收缩。窗口不是固定大小所以用while // 4. 窗口不满足条件 ......
LeetCode LeetCode3 字符 Hot 100

[LeetCode Hot 100] LeetCode438. 找到字符串中所有字母异位词

题目描述 思路:滑动窗口模板 需要维护的变量: // 1. 用于存放结果 List<Integer> res = new ArrayList<>(); // 2. 定义需要维护的变量:根据题意可知是一个哈希表 Map<Character, Integer> map = new HashMap<>() ......
LeetCode 字符串 字母 字符 Hot

LeetCode567. 字符串的排列

题目描述 思路:滑动窗口模板 定义需要维护的变量 Map<Character, Integer> map = new HashMap<>(); Map<Character, Integer> map_s1 = new HashMap<>(); for (char c : s1.toCharArray ......
字符串 字符 LeetCode 567

LeetCode643. 子数组最大平均数I

题目描述 思路:滑动窗口模板 定义需要维护的变量 // 1. 定义需要维护的变量 double sum = 0; double max_avg = Integer.MIN_VALUE; 窗口固定大小为k,所以用if if (end - start + 1 == k) { sum -= nums[st ......
平均数 数组 LeetCode 643

[LeetCode] 1266. Minimum Time Visiting All Points

On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the ord ......
LeetCode Visiting Minimum Points 1266

Leetcode刷题day4-哈希表.异位词.交集.快乐数.两数和

242.有效的字母异位词 242. 有效的字母异位词 - 力扣(LeetCode) 给定两个字符串 _s_ 和 _t_ ,编写一个函数来判断 _t_ 是否是 _s_ 的字母异位词。 注意: 若 _s_ 和 _t_ 中每个字符出现的次数都相同,则称 _s_ 和 _t_ 互为字母异位词。 示例 1: 输 ......
交集 Leetcode day4 day

LeetCode-Java:121. 买卖股票的最佳时机

题目 给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 ......
LeetCode-Java 时机 LeetCode 股票 Java

LeetCode-Java:122. 买卖股票的最佳时机Ⅱ

题目 给你一个整数数组 prices ,其中 prices[i] 表示某支股票第 i 天的价格。 在每一天,你可以决定是否购买和/或出售股票。你在任何时候 最多 只能持有 一股 股票。你也可以先购买,然后在 同一天 出售。 返回 你能获得的 最大 利润 。 示例 1: 输入:prices = [7, ......
LeetCode-Java 时机 LeetCode 股票 Java

[LeetCode Hot 100] LeetCode1. 两数之和

题目描述 思路: 如果哈希表存在target-nums[i],则返回索引下标i和对应的key值(可以按任意顺序返回答案) 如果哈希表中不存在target-nums[i],则存入nums[i]和对应的索引值 方法一:哈希表 class Solution { public int[] twoSum(in ......
LeetCode 之和 LeetCode1 Hot 100

代码随想录算法训练营第4天 | leetcode24、leetcode19、leetcode面试题02

(本合集全部为Go语言实现) 相关文章链接:24题解 19题解 02.07题解 142题解 相关视频链接: Leetcode24 状态:秒了 实现过程中的难点:对组内两个节点的指针指向流转需要倒腾明白。临时头结点真的很有用 个人写法 func swapPairs(head *ListNode) *L ......
leetcode 随想录 训练营 随想 算法

代码随想录算法训练营第3天 | leetcode203、leetcode707、leetcode206

(本合集全部为Go语言实现) 相关文章链接:203题解 707题解 206题解 相关视频链接: Leetcode203 状态:秒了 实现过程中的难点:链表遍历一定要记得指针后移。另外,在头指针前加入一个新的临时头节点可以统一整个遍历过程,否则需要先确定初始时两指针的状态 个人写法 /** * Def ......
leetcode 随想录 训练营 随想 算法

[LeetCode Hot 100] LeetCode15. 三数之和

题目描述 思路 特判:对于数组长度为n,如果数组为null或者数组长度小于3,返回[]。 对数组进行排序。 遍历排序后的数组: 若 nums[i]>0nums[i]>0nums[i]>0:因为已经排序好,所以后面不可能有三个数加和等于 000,直接返回结果。 对于重复元素:跳过,避免出现重复解。 令 ......
LeetCode 之和 Hot 100 15

[LeetCode Hot 100] LeetCode160. 相交链表

题目描述 思路 方法一: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = nu ......
LeetCode Hot 100 160
共1640篇  :6/55页 首页上一页6下一页尾页