当前位置:首页|资讯

GFG 95 Valuable String

作者:您是打尖儿还是住店呢发布时间:2024-09-24


You are given an array arr of n strings. The strings consist of lowercase Latin letters. The value of each string is de ned as the difference between the number of consonants and vowels. You have

to  nd the string with the maximum value. If there is a tie between some strings, the first one

should be returned.


Example 1:


Input:

n = 3

arr = {"house","car","tree"}

Output:

"house"

Explanation:

The strings "house" and "car" both have value 1. So, "house" should be answer.

-------

就是判断字符串中元音跟辅音数字差,写个函数即可,然后每次遇到最大的,更新最大值,跟相应的索引即可,只是max初始要设置成-1,不能是0,WA了一次。



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1