Leetcode-1085 sum of digits in the minimum number(最小元素各数位之和)

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2
 3 class Solution
 4 {
 5     public:
 6         int sumOfDigits(vector<int>& A)
 7         {
 8             int mm = A[0];
 9             _for(i,0,A.size())
10             {
11                 if(A[i]<mm)
12                     mm = A[i];
13             }
14             int S = 0;
15             while(mm)
16             {
17                 S += mm%10;
18                 mm /= 10;
19             }
20             if(S&0x1)
21                 return 0;
22             return 1;
23         }
24 };

我见过的有史以来力扣周赛出过的最简单的题

原文地址:https://www.cnblogs.com/Asurudo/p/11029387.html

时间: 2024-08-30 06:25:52

Leetcode-1085 sum of digits in the minimum number(最小元素各数位之和)的相关文章

[LeetCode] 129 Sum Root to Leaf Numbers 求根到叶节点数字之和

此题题意是求所有从根结点到叶节点的路径转化为数字后之和. 因为是二叉树,容易想到是用递归求解. 整体思想是从根到叶子进行遍历,其中不断保存当前的中间结果(上一层的结果乘以10后加上当前层根节点的数值)并通过参数向下传递... 到达叶子节点时可以逐层返回最终结果.解法不难,但有几个细节需要考虑清楚. 1)可以用递归函数dfs的参数表内置的返回和来返回数值,也可以直接用dfs返回值,对应于以下两种定义: void dfs(TreeNode *root, int &sum, int pre); int

Sum of Digits is Prime

Sum of Digits is Prime Daoyi Peng August 19, 2014 For an integer $q\geqslant2$ let $s_q(n)$ denote the $q$-ary sum-of-digits function of a non-negative integer $n$, that is, if $n$ is given by its $q$-ary digits expansion $n=\sum\limits_{k=0}^{r} a_k

Codeforces Round #277.5 (Div. 2)C. Given Length and Sum of Digits...(贪心)

传送门 Description You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the d

Codeforces Round #277.5 (Div. 2)——C贪心—— Given Length and Sum of Digits

You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base with

CF 489 C Given Length and Sum of Digits... 贪心

题目链接:http://codeforces.com/problemset/problem/489/C 题目大意:给定位数和各个位的和,问满足条件数字的最大值,最小值. 解题思路:模拟即可.主要是细节判断. 代码: 1 const int inf = 0x3f3f3f3f; 2 const int maxn = 1e2 + 5; 3 int m, s; 4 char ans1[maxn], ans2[maxn]; 5 6 void solve(){ 7 memset(ans1, 0, sizeo

LeetCode OJ - Sum Root to Leaf Numbers

这道题也很简单,只要把二叉树按照宽度优先的策略遍历一遍,就可以解决问题,采用递归方法越是简单. 下面是AC代码: 1 /** 2 * Sum Root to Leaf Numbers 3 * 采用递归的方法,宽度遍历 4 */ 5 int result=0; 6 public int sumNumbers(TreeNode root){ 7 8 bFSearch(root,0); 9 return result; 10 } 11 private void bFSearch(TreeNode ro

leetcode -- 3 sum

3-sum 题目描述: 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. 题目要求: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ 

LeetCode:Range Sum Query - Immutable - 数组指定区间内的元素和

1.题目名称 Range Sum Query(数组指定区间内的元素和) 2.题目地址 https://leetcode.com/problems/range-sum-query-immutable/ 3.题目内容 英文:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. 中文:给定一个数组nums,求出索引i和j之间元素的和,i一定是小于或等于j

[leetcode]Combination Sum @ Python

原题地址:https://oj.leetcode.com/problems/combination-sum/ 题意: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited