{"id":7247,"date":"2020-08-15T21:25:28","date_gmt":"2020-08-16T04:25:28","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=7247"},"modified":"2020-08-15T21:26:48","modified_gmt":"2020-08-16T04:26:48","slug":"leetcode-1550-three-consecutive-odds","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/algorithms\/array\/leetcode-1550-three-consecutive-odds\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1550. Three Consecutive Odds"},"content":{"rendered":"\n<p>Given an integer array&nbsp;<code>arr<\/code>, return&nbsp;<code>true<\/code>&nbsp;if there are three consecutive odd numbers in the array. Otherwise, return&nbsp;<code>false<\/code>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> arr = [2,6,4,1]\n<strong>Output:<\/strong> false\n<strong>Explanation:<\/strong> There are no three consecutive odds.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> arr = [1,2,34,3,4,5,7,23,12]\n<strong>Output:<\/strong> true\n<strong>Explanation:<\/strong> [5,7,23] are three consecutive odds.\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>1 &lt;= arr.length &lt;= 1000<\/code><\/li><li><code>1 &lt;= arr[i] &lt;= 1000<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Counting<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(n)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\nclass Solution {\npublic:\n  bool threeConsecutiveOdds(vector<int>& arr) {       \n    int count = 0;\n    for (int x : arr) {\n      if (x & 1) {\n        if (++count == 3) return true;\n      } else {\n        count = 0;\n      }\n    }\n    return false;      \n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given an integer array&nbsp;arr, return&nbsp;true&nbsp;if there are three consecutive odd numbers in the array. Otherwise, return&nbsp;false. Example 1: Input: arr = [2,6,4,1] Output: false Explanation:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[8,222,408],"class_list":["post-7247","post","type-post","status-publish","format-standard","hentry","category-array","tag-counting","tag-easy","tag-odd","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=7247"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7247\/revisions"}],"predecessor-version":[{"id":7249,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7247\/revisions\/7249"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=7247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=7247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=7247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}