欢迎光临散文网 会员登陆 & 注册

leetcode 1550 Three Consecutive Odds

2022-03-07 21:14 作者:您是打尖儿还是住店呢  | 我要投稿

Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.

 

Example 1:

Input: arr = [2,6,4,1]Output: falseExplanation: There are no three consecutive odds.

Example 2:

Input: arr = [1,2,34,3,4,5,7,23,12]Output: trueExplanation: [5,7,23] are three consecutive odds.

 

Constraints:

  • 1 <= arr.length <= 1000

  • 1 <= arr[i] <= 1000

就是循环一次,max记住一下连续最多的奇数的数量,然后大于等于3返回true;否则false;

Runtime: 0 ms, faster than 100.00% of Java online submissions for Three Consecutive Odds.

Memory Usage: 42.5 MB, less than 41.25% of Java online submissions for Three Consecutive Odds.


leetcode 1550 Three Consecutive Odds的评论 (共 条)

分享到微博请遵守国家法律