首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏leetcode_solutions

    Sum

    Find all unique quadruplets in the array which gives the sum of target. 

    77920发布于 2019-03-14
  • 来自专栏python3

    Sum

    A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. ... => 1 + 1 => 2 My solution: def digital_root(n): lst = [int(x) for x in str(n)] result = sum return digital_root(result) Best solution: def digital_root(n): return n if n < 10 else digital_root(sum

    69410发布于 2020-01-16
  • 来自专栏calmound

    Path Sum

    问:二叉树是否存在路径和等于sum的路径,若存在输出true,否则输出false 分析:递归调用二叉树,每次将上一层的val值传递给子结点并加上子节点的val,当传递到某个结点为叶子结点时,判断其val 值是否等于sum 错点:二叉树为空,则无论sum为多少都为false,这个容易造成RE         二叉树只有根节点,则直接判断其值与sum的关系 class Solution { public: ->val,sum,flag); } bool hasPathSum(TreeNode *root, int sum) { if(root==NULL) || PathSum(root->right,sum,val); } bool hasPathSum(TreeNode *root, int sum) { return PathSum(root,sum,0); } };

    1.5K30发布于 2018-04-17
  • 来自专栏但老师的数据分析

    SUM for Summer

    SUM for Summary 即求和 在不知道SUM之前 我们天然的会使用加号+ 这样也没问题 殊途同归 就是有点累手指头 在知道了SUM之后 我们学会在在单元格输入 =SUM(... 求和 一开始我还是习惯在SUM里面输入加号+ 像这样 好像也没什么不对啊 但是输入多几次之后 我发现它总提示我用逗号 索德斯呢 所以我试了下 又对了 可是我的手指头还是有点酸 每次都要点 点标签12次,点单元格12次,输入逗号11次,按Enter1次 一共操作只有仅仅的36次 其实你可以在B2单元格输入 =SUM('*'! B2) 然后按下Enter 神奇的事情就发生了 怕你们不信 所以我特意录了一个GIF给你们看 注意 SUM只会求和数字 非数字是不会求和的 也会被自动忽略 所以可以尽情拉 比如这样 遇到文本型数字也不会求和

    77520编辑于 2022-03-22
  • 来自专栏小二的折腾日记

    LeetCode-15-3Sum&&4Sum

    15. 3Sum Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. example, given array S = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] 同之前的2sum Find all unique quadruplets in the array which gives the sum of target. 其实跟前面的3sum解决的办法是一样的,无非这里为了减少一点复杂度,借用了一下大家使用的方法。,在每次遍历的时候进行一点判断,以减少循环的次数。

    79210发布于 2018-08-07
  • 来自专栏SnailTyan

    Two Sum

    for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { int sum = nums[i] + nums[j]; if(sum == target) { result[0] = i;

    79030发布于 2019-05-25
  • 来自专栏米扑专栏

    【leetcode】Path Sum

    Question: 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 / \ \ 7 2 1 return true, as there exist a root-to-leaf path 5->4->11->2 which sum ) function if(root == NULL){ return false; } int sub = sum

    71050发布于 2019-02-19
  • 来自专栏程序编程之旅

    POJ 1844 Sum

    associating to each number a sign (+ or -) and calculating the value of this expression we obtain a sum The problem is to determine for a given sum S the minimum number N for which we can obtain S by associating The only line contains in the first line a positive integer S (0< S <= 100000) which represents the sum Output The output will contain the minimum number N for which the sum S can be obtained.

    53320发布于 2021-01-20
  • 来自专栏calmound

    Minimum Path Sum

    问题:从左上角到右下角的最小路径和 class Solution { public: int num[300][300]; int dfs(int x,int y,vector<vector<int> >&grid) { if(x==grid.size()-1 && y==grid[0].size()-1) return grid[x][y]; if(num[x][y]) return num[x][y]; int h1=99999,h

    74640发布于 2018-04-17
  • 来自专栏SnailTyan

    Path Sum II

    right(NULL) {} * }; */ class Solution { public: vector<vector<int>> pathSum(TreeNode* root, int sum root) { return result; } vector<int> path; tranverseTree(root, sum , result, path); return result; } void tranverseTree(TreeNode* root, int sum, vector vector<int>>& result, vector<int> path) { path.push_back(root->val); if(root->val == sum , result, path); return result; } void tranverseTree(TreeNode* root, int sum, vector

    65810发布于 2019-05-25
  • 来自专栏蛮三刀的后端开发专栏

    Minimum Path Sum

    从一个矩阵的左上角出发到右下角,只能向右或向下走,找出哪一条路径上的数字之和最小。

    85320发布于 2019-03-26
  • 来自专栏米扑专栏

    【leetcode】Two Sum

    *log(n)) int l = 0; int r = len - 1; while(l < r){ int sum = nums[l].val + nums[r].val; if(sum == target){ ret[0] = min(nums[l].idx ret[1] = max(nums[l].idx, nums[r].idx); break; } else if(sum

    60740发布于 2019-02-19
  • 来自专栏人工智能与演化计算成长与进阶

    matlab sum函数

    matlab sum函数 sum 求和函数 默认按列求和 二维矩阵,按列求和 b1=sum(a,1) 二维矩阵,按行求和 b2=sum(a,2) format compact a=[1,2,3;4,5,6 ;7,8,9] b0=sum(a) b1=sum(a,1) b2=sum(a,2) % a = % 1 2 3 % 4 5 6 % 7

    1.3K20发布于 2020-08-14
  • 来自专栏labuladong的算法专栏

    一个函数秒杀 2Sum 3Sum 4Sum 问题

    但是除了 twoSum 问题,LeetCode 上面还有 3Sum,4Sum 问题,我估计以后出个 5Sum,6Sum 也不是不可能。 那么,对于这种问题有没有什么好办法用套路解决呢? 和 4Sum 的时候会复用这个函数。 ,4Sum 完全就可以用相同的思路:穷举第一个数字,然后调用 3Sum 函数计算剩下三个数,最后组合出和为 target 的四元组。 四、100Sum 问题? 在 LeetCode 上,4Sum 就到头了,但是回想刚才写 3Sum 和 4Sum 的过程,实际上是遵循相同的模式的。 我相信你只要稍微修改一下 4Sum 的函数就可以复用并解决 5Sum 问题,然后解决 6Sum 问题…… 那么,如果我让你求 100Sum 问题,怎么办呢?

    96610发布于 2021-09-23
  • 来自专栏小浩算法

    漫画:经典鹅厂面试题(2Sum,3Sum,4Sum

    该题为 二数之和 的进阶版本,当然还有一个进阶版本为 四数之和。我们将会一一进行分析!

    78630发布于 2020-04-14
  • 来自专栏null的专栏

    LeetCode——Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number.

    39930发布于 2019-02-13
  • 来自专栏Reck Zhang

    ACMSGURU 123 - The sum

    The sum Problem Description The Fibonacci sequence of numbers is known: F1 = 1; F2 = 1; Fn+1 = Fn + Fn You have to find S - the sum of the first K Fibonacci numbers.

    56240发布于 2021-08-11
  • 来自专栏SnailTyan

    Sum of Two Integers

    Solution Version 1 class Solution { public: int getSum(int a, int b) { int sum = 0; int carry = 0; while(b) { sum = a ^ b; carry = a & b; a = sum; b = carry << 1; } return sum;; } }; Version 2 class Solution

    39110发布于 2019-05-25
  • 来自专栏YashanDB知识库

    YashanDB SUM函数

    SUM语法图SUM函数计算给定参数expr的数值和,其返回值类型如下:expr类型返回值TINYINT、SMALLINTBIGINTINT、BIGINTNUMBERFLOATFLOATDOUBLEDOUBLE (employee_count) sum FROM branches1 GROUP BY area_no;AREA_NO SUM------- ------------- (revenue_total) curr,SUM(SUM(revenue_total)) OVER (PARTITION BY year ORDER BY month ROWS BETWEEN UNBOUNDED (employee_count) sum FROM branches1 GROUP BY area_no;AREA_NO SUM------- ------------- (revenue_total) curr,SUM(SUM(revenue_total)) OVER (PARTITION BY year ORDER BY month ROWS BETWEEN UNBOUNDED

    25910编辑于 2025-08-04
  • 来自专栏给永远比拿愉快

    Leetcode: Path Sum

    题目: 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 / \ ; } return dfs(node->left, sum, cursum + node->val) || dfs(node->right, sum, cursum + node->val); } public: bool hasPathSum(TreeNode *root, int sum) { return dfs(root, sum

    57820发布于 2019-01-22
领券