1.原题:

https://leetcode.com/problems/find-numbers-with-even-number-of-digits/

Given an array nums of integers, return how many of them contain an even number of digits.

翻译:给定一个整数数组,输出拥有偶数数位的数字的数量。

理论上的输入输出:

Input: nums = [555,901,482,1771]
Output: 1

2.解题思路:

遇到这种需要区别偶奇数的情况,通常都应该想到要用 % 运算符,不过这次我们的目的不是查看数字本身是不是偶数,所以需要用到 to_string(int) 这个函数,可以把 int 转换成string。

然后再用size()来看string的长度,再把长度 % 2 就可以得知是否是偶数。

class Solution {
public:
int findNumbers(vector<int>& nums) {
return count_if(nums.begin(), nums.end(), [](const auto& a) {
return to_string(a).size() % 2 == 0;
});
}
};

引用:https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/457606/javaPython-3-1-liners.

leetcode菜鸡斗智斗勇系列(5)--- 寻找拥有偶数数位的数字的更多相关文章

  1. leetcode菜鸡斗智斗勇系列(4)--- 单一数字的乘积和总合的减法

    1.原题: https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ Given an i ...

  2. leetcode菜鸡斗智斗勇系列(3)--- Jewels and Stones珠宝和钻石

    1.原题: https://leetcode.com/problems/jewels-and-stones/ You're given strings J representing the types ...

  3. leetcode菜鸡斗智斗勇系列(2)--- 把一个ipv4地址转换成一串数字

    1.原题: https://leetcode.com/problems/defanging-an-ip-address/ 这道题本身很简单, Given a valid (IPv4) IP addre ...

  4. leetcode菜鸡斗智斗勇系列(1)---把一个链表中的二进制数字转换为一个整型数(int)

    Convert Binary Number in a Linked List to Integer这道题在leetcode上面算作是“easy”,然而小生我还是不会做,于是根据大佬的回答来整理一下思路 ...

  5. leetcode菜鸡斗智斗勇系列(10)--- Decrypt String from Alphabet to Integer Mapping

    1.原题: https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/submissions/ Giv ...

  6. leetcode菜鸡斗智斗勇系列(9)--- Range Sum of BST

    1.原题: https://leetcode.com/problems/range-sum-of-bst/ Given the root node of a binary search tree, r ...

  7. leetcode菜鸡斗智斗勇系列(8)--- Find N Unique Integers Sum up to Zero

    1.原题: https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/ Given an integer n, retur ...

  8. leetcode菜鸡斗智斗勇系列(7)--- 用最小的时间访问所有的节点

    1.原题: https://leetcode.com/problems/minimum-time-visiting-all-points/ On a plane there are n points ...

  9. leetcode菜鸡斗智斗勇系列(6)--- 检查一个string里面有几个对称的字段

    1.原题: https://leetcode.com/problems/split-a-string-in-balanced-strings/ Split a String in Balanced S ...

随机推荐

  1. 原生java与js结合

    链接:https://www.jb51.cc/html5/15606.html

  2. vue中,实现锚点定位及跳转(url不发生变化)

    <div class="footer" @click="returnTop"> methods:{ returnTop:function(){ do ...

  3. C语言:使用递归解决汉诺塔问题。

    //汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具.大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘.大梵天命令婆罗门把圆盘从下面开始按大小 ...

  4. Codeforces 1313C.Skyscrapers

    题目链接 题意是给你一个数组,问你如何建造,使得每个点都不小于其左右的点,包括不相邻的点 分析题意,容易得知,就是找一个点两侧的不上升序列且带修,那我们就分别从头跑一遍,从尾跑一遍,两者相加就是每个点 ...

  5. WordPress搭建教程---购买域名+购买VPS主机+域名DNS解析+网站环境+上传网站程序

    WordPress搭建教程 购买域名---NameSilo 购买VPS主机---Vultr 域名DNS解析 网站环境 上传网站程序 参考文章: 1. WordPress搭建教程 https://zhu ...

  6. POJ-3821-Dining (拆点网络流)

    这题为什么不能用 左边放食物,中间放牛,后面放水? 原因很简单,假设一头牛喜欢两个食物AB和两种水AB. 此时可以从一个食物A,走到牛A,再走到水A. 但是还可以有另一条路,从另一个食物B,走到该牛A ...

  7. vs2008每次build都会重新编译链接 && 项目已经过期

    转自:http://blog.csdn.net/movezzzz/article/details/6816605 无外乎两种情况: 1.时间问题,所创建的文件的时间比如是:2011-09-22 09: ...

  8. FileUpload之FileItem类的常用方法

    http://blog.csdn.net/chinaliuyan/article/details/7002014

  9. Android 调用系统Email发送带多附件的邮件

    转自:http://www.open-open.com/lib/view/open1347005126912.html 众所周知,在Android中调用其他程序进行相关处理,都是使用的Intent.当 ...

  10. 两个list 集合比较属性不同的值

    for(Stall stall : stallList){ boolean flag = false; for(DeliveryStallCommission deliveryStallCommiss ...