代码(Python3) MAX: int = 0x3f3f3f3f class Solution: def destroyTargets(self, nums: List[int], space: int) -> int: # remain_to_info[remain] = (min_num, cnt) # remain: nums[i] 模 space 的余数 # min_num: nums 中模 space 余 remain 的最小的数 # cnt: nums 中模 space 余 ...
// 初始嵌套信封个数为 0 时,最外层信封的最小高度为 0 ,方便后续处理。 minHeight := []int{ 0 } // 遍历每个信封 for _, envelope := range envelopes { // 寻找 minHeight 中第一个大于等于 envelope[1] 的下标 k , // 则说明以当前信封为最外层时,最多能嵌套 k 层 k := sort.Search(...
tmp_set=set(tmp)# 如果集合中只有一个元素,即证明全都为同一字符iflen(tmp_set)==1:res+=tmp[0]else:breakreturnres #作者:wu_yan_zu #链接:https://leetcode-cn.com/problems/longest-common-prefix/solution/shui-ping-sao-miao-zhu-xing-jie-shi-python3-by-zhu/ 这个确实,基本思路是省略掉找最短...
执行用时 : 864 ms, 在所有 Python3 提交中击败了37.48% 的用户 内存消耗 : 14.3 MB, 在所有 Python3 提交中击败了26.60% 的用户 英文版结果: Runtime: 1108 ms, faster than 28.08% of Python3 online submissions for Two Sum. Memory Usage: 14.6 MB, less than 20.00% of Python3 online submission...
// 和为 K 的子数组(LeetCode 560):https://leetcode.cn/problems/subarray-sum-equals-k/ classSolution{ publicintsubarraySum(int[] nums,intk){ // 统计和为 K 的子数组的数量 intcount =0; // 记录遍历到索引为 i 的这个元素时,前缀和的值是多少 ...
This website is used to record the process of solving problems inLeetCode. On the one hand, I can develop a habit of solving problems, on the other hand, I can motivate myself to challenge difficulties one after another. If you are interested in it, please join us!
[leetcode]3Sum @ Python 原题地址:http://oj.leetcode.com/problems/3sum/ 题意:从一个数组中找到三个数,使这三个数的和为0。有可能存在多组解,也有可能存在重复的解,所以需要去重。比如:num=[-1,0,1,2,-1,-4];那么存在两组解:[[-1,0,1],[-1,-1,2]],解中的数需要是从小到大排序状态。
题目地址:https://leetcode.com/problems/path-sum-ii/description/ 题目描述 Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. Note: A leaf is a node with no children. Example: ...
【LeetCode】3. Longest Substring Without Repeating Characters 解题报告(Python & C++) 目录 题目描述 题目大意 解题方法 解法一:虫取法+set 方法二:一次遍历+字典 日期 题目地址:https://leetcode.com/problems/longest-substring-without-repeating-characters/description/...
Python vezzolter/DSA Star8 Learn and practice the entire DSA in a simple and structured way with this C++ repository. learningcomputer-sciencealgorithmsleetcodecppdata-structures UpdatedMay 16, 2025 C++ naidu199/DSA Star3 DSA problems in Leetcode and Geeks for Geeks ...