题目如下: Given an array nums of integers, we need to find the maximum possible sum of elements of the array such that it is divisible by three. Example 1: Input: nums = [3,6,5,1,8] Output: 18 Explanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maxi…
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-sum-of-averages/description/ 题目描述: We partition a row of numbers A into at most…
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/path-sum-ii/description/ 题目描述: Given a binary tree and a sum, find all root-to-leaf paths where each…
Difficulty:easy  More:[目录]LeetCode Java实现 Description Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbe…
Difficulty:easy  More:[目录]LeetCode Java实现 Description Design and implement a TwoSum class. It should support the following operations: addand find.add(input) – Add the number input to an internal data structure.find(value) – Find if there exists any…
[Question] Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + n…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 前缀和求余 日期 题目地址:https://leetcode.com/problems/subarray-sums-divisible-by-k/ 题目描述 Given an array A of integers, return the number of (contiguous, non-empty) subarrays that ha…
题目如下: Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K. Example 1: Input: A = [4,5,0,-2,-3,1], K = 5 Output: 7 Explanation: There are 7 subarrays with a sum divisible by K = 5: [4, 5,…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/binary-prefix-divisible-by-5/ 题目描述 Given an array A of 0s and 1s, consider N_i: the i-th subarray from ```A[0]toA[i]`` interpreted as a bi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/smallest-integer-divisible-by-k/ 题目描述 Given a positive integer K, you need find the smallest positive integer N such that N is divisible b…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 小根堆 日期 题目地址:https://leetcode.com/problems/maximize-sum-of-array-after-k-negations/ 题目描述 Given an array A of integers, we must modify the array in the following way: we choose a…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode.com/contest/weekly-contest-110/problems/range-sum-of-bst/ 题目描述 Given the root node of a binary search tree, return the sum of values of all nodes wi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/#/description 题目描述 Given an array of integers that is already sorted in ascending order,…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:two sum, 两数之和,题解,leetcode, 力扣,Python, C++, Java 目录 题目描述 题目大意 解题方法 字典+两次遍历 字典+一次遍历 双指针 日期 题目地址:https://leetcode.com/problems/two-sum/#/description 题目描述 Given an array of integers,…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS + DFS BFS + DFS 日期 题目地址:https://leetcode.com/problems/path-sum-iii/#/description 题目描述 You are given a binary tree in which each node contains an integer value. Find the num…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 预先求和 相似题目 参考资料 日期 题目地址:https://leetcode.com/problems/range-sum-query-2d-immutable/description/ 题目描述 Given a 2D matrix matrix, find the sum of the elements inside the rectangle…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 日期 题目地址:https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/ 题目描述 Given a Binary Search Tree and a target number, return true if there exist two…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/description/ 题目描述: Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix su…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/description/ 题目描述: In a given array nums of positive integers, find three non-overlapping subarrays with maximum su…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 保存累积和 日期 题目地址:https://leetcode.com/problems/range-sum-query-immutable/description/ 题目描述 Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), in…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 方法二:回溯法 日期 题目地址:https://leetcode.com/problems/combination-sum-ii/description/ 题目描述 Given a collection of candidate numbers (candidates) and a target number (target), fi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/subarray-sum-equals-k/description/ 题目描述 Given an array of integers and an integer k, you need to find the total number of continuous subar…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 前缀树 日期 题目地址:https://leetcode.com/problems/map-sum-pairs/description/ 题目描述 Implement a MapSum class with insert, and sum methods. For the method insert, you'll be given a pai…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 文章目录 题目描述 题目大意 解题方法 BFS DFS 日期 题目地址: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…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetcode.com/problems/target-sum/description/ 题目描述 You are given a list of non-negative integers, a1, a2, -, an, and a target, S. Now you have 2 symbols +…
Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time.   动态规划即可,与Unique…
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. 思路:由于只能向两个方向走,瞬间就没有了路线迂回的烦恼,题目的难度…
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. 思路: 这题不要想得太复杂,什么搜索策略什么贪心什么BFS DFS…
题目描述: Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. 解题思路: 根据题意,寻找二维数组中所有可以组成的矩形中面积不超过k的最大值,所以必须要求出可能组成的矩形的面积并与k比较求出最终结果.这里为了最终不超时,可以在一下方面进行优化: 1.设置一个数组比较当前列(或…
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example:Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ \ 7 2 1 return…