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. [C++_QT] 同步方式提交GET和POST请求

    #开始 最近在做一个需要用到提交HTTP请求的工具 但是遇到一个问题 如下 在Qt中提交一个get请求之后(或者post) 在收到回复之后会调用之前连接好的槽函数 但是问题就是在主调函数中不知道什么时 ...

  2. 解决 上下拉的橡皮筋 和 复制无效 和 ios滑动屏幕定时器停止问题cordova

    cordova 安装插件cordova plugin add cordova-plugin-wkwebview-engine@latest --save config.xml 的 <platfo ...

  3. Java数字和字符的对照关系表

    /* 数字和字符的对照关系表(编码表): ASCII码表:American Standard Code for Information Interchange,美国信息交换标准代码. Unicode码 ...

  4. family_to_level函数

    #include <netinet/in.h> #include <sys/socket.h> int family_to_level(int family) { switch ...

  5. centos610无桌面安装JDK

     Centos610系列配置 1.使用yum查找jdk: yum search java|grep jdk    2.选择安装截图中选中的版本 yum install java-1.8.0-openj ...

  6. java月利率计算(等额本息贷款)

    等额本息 每月还款计算公式: 每月本息金额 = (本金×月利率×(1+月利率)^还款月数)÷ ((1+月利率)^还款月数-1)) 反转求出 月利率 月利率 如果根据上面公式反转是算不出来的. 下面给出 ...

  7. spring boot加载配置文件的顺序

    四个默认加载配置文件地方的优先级,四个文件相同配置有优先级概念  不同位置相互补充 外部配置文件不建议使用,不符合maven项目结构,打包会打不进去

  8. 修改oracle数据库用户密码的方法

    WIN+R打开运行窗口,输入cmd进入命令行: 输入sqlplus ,输入用户名,输入口令(如果是超级管理员SYS的话需在口令之后加上as sysdba)进入sql命令行:    连接成功后,输入“s ...

  9. netty代理http&https请求

    (1)关键代码 package test; import java.security.cert.CertificateException; import javax.net.ssl.SSLExcept ...

  10. mybatis源码探索笔记-4(缓存原理)

    前言 mybatis的缓存大家都知道分为一级和二级缓存,一级缓存系统默认使用,二级缓存默认开启,但具体用的时候需要我们自己手动配置.我们依旧还是先看一个demo.这儿只贴出关键代码 public in ...