【leetcode】 15. 三数之和-编程思维
题目 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。 注意:答案中不可以包含重复的三元组。 示例 1: 输入:nums = [-1,0,1,2,-1,-4] 输出:[[-1,-1,2],[-1,0,1]] 示例 2: 输入:nums = [] 输出:[] 示例 3: 输入
morethink program
题目 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。 注意:答案中不可以包含重复的三元组。 示例 1: 输入:nums = [-1,0,1,2,-1,-4] 输出:[[-1,-1,2],[-1,0,1]] 示例 2: 输入:nums = [] 输出:[] 示例 3: 输入
原题链接在这里:https://leetcode.com/problems/count-sub-islands/ 题目: You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is
原题链接在这里:https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/ 题目: You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening bracke
原题链接在这里:https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string/ 题目: Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced
重复的子字符串 题目描述:给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过10000。 示例说明请见LeetCode官网。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/repeated-substring-pattern/ 著作权归领扣网络所有。商业转载请联系官方授权,非商
下一个更大元素 I 题目描述:给你两个 没有重复元素 的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集。 请你找出 nums1 中每个元素在 nums2 中的下一个比其大的值。 nums1 中数字 x 的下一个更大元素是指 x 在 nums2 中对应位置的右边的第一个比 x 大的元素。如果不存在,对应位置输出 -1 。 示例说明请见LeetCode官网。 来源:力扣
题目链接 https://leetcode-cn.com/problems/add-two-numbers/ 题目描述 给你两个非空的链表,表示两个非负的整数。它们每位数字都是按照逆序的方式存储的,并且每个节点只能存储一位数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可以假设除了数字0之外,这两个数都不会以0开头。 示例如下: 输入:l1 = [2,4,3], l2 = [5,
最大连续 1 的个数 题目描述:给定一个二进制数组, 计算其中最大连续 1 的个数。 示例说明请见LeetCode官网。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/max-consecutive-ones/ 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 解法一:数组遍历 首先,考虑特殊情况,如果原数组为空
找到所有数组中消失的数字 题目描述:给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1, n] 内。请你找出所有在 [1, n] 范围内但没有出现在 nums 中的数字,并以数组的形式返回结果。 示例说明请见LeetCode官网。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/find-all-numbers-
颠倒二进制位 题目描述:颠倒给定的 32 位无符号整数的二进制位。 提示: 请注意,在某些语言(如 Java)中,没有无符号整数类型。在这种情况下,输入和输出都将被指定为有符号整数类型,并且不应影响您的实现,因为无论整数是有符号的还是无符号的,其内部的二进制表示形式都是相同的。 在 Java 中,编译器使用二进制补码记法来表示有符号整数。因此,在上面的 示例 2 中,输入表示有符号整数
原题链接在这里:https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/ 题目: You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list. Th
重复的DNA序列 题目描述:所有 DNA 都由一系列缩写为 'A','C','G' 和 'T' 的核苷酸组成,例如:"ACGAATTCCG"。在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助。 编写一个函数来找出所有目标子串,目标子串的长度为 10,且在 DNA 字符串 s 中出现次数超过一次。 示例说明请见LeetCode官网。 来源:力扣(LeetCode) 链接:ht
排列硬币 题目描述:你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币。 给定一个数字 n,找出可形成完整阶梯行的总行数。 n 是一个非负整数,并且在32位有符号整型的范围内。 示例说明请见LeetCode官网。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/arranging-coins/ 著作权归
原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/ 题目: Given the root of a binary tree, return the lowest common ancestor (LCA) of two given nodes, p and q. If either n
原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/ 题目: Given two nodes of a binary tree p and q, return their lowest common ancestor (LCA). Each node will have a refer
原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv/ 题目: Given the root of a binary tree and an array of TreeNode objects nodes, return the lowest common ancestor (LCA) o
1 题目描述 题目来源: https://leetcode-cn.com/problems/binary-gap/ 给定一个正整数 n,找到并返回 n 的二进制表示中两个 相邻 1 之间的 最长距离 。如果不存在两个相邻的 1,返回 0 。 如果只有 0 将两个 1 分隔开(可能不存在 0 ),则认为这两个 1 彼此 相邻 。两个 1 之间的距离是它们的二进制表示中位置的绝对差。例如,"1
1 题目描述 题目来源: https://leetcode-cn.com/problems/reformat-date 给你一个字符串 date ,它的格式为 Day Month Year ,其中: Day 是集合 {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"} 中的一个元素。 Month 是集合 {"Jan", "Feb", "Mar",
完全平方数 题目描述:给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。 给你一个整数 n ,返回和为 n 的完全平方数的 最少数量 。 完全平方数 是一个整数,其值等于另一个整数的平方;换句话说,其值等于一个整数自乘的积。例如,1、4、9 和 16 都是完全平方数,而 3 和 11 不是。 示例说明请见L