#261. 检查数组中的271模式
检查数组中的271模式
Check 271 Pattern
Background
Dawei is studying a special number sequence. He wants to know if a specific pattern exists in an integer array.
Problem Description
Given an array of integers, return true if it contains a pattern.
A pattern refers to a value, followed by the value plus , followed by the value minus .
Additionally, the pattern counts even if the third value differs by or less from the correct value (value minus ).
For example, if the first value is , the second is , and the third is , then a pattern exists if .
Input Format
Input is given from standard input in the following format.
A single line containing several integers, separated by spaces.
Output Format
Output is printed to standard output in the following format.
Output
trueif a pattern exists in the array; otherwise, outputfalse.
Sample
1 2 7 1
true
1 2 8 1
false
2 7 1
true
Sample Explanation
- Sample 1: Array
[1 2 7 1]. When , the second element is , and the third element is . Since , a pattern exists. - Sample 2: Array
[1 2 8 1]. When , the second element is , which is not equal to . Therefore, no pattern exists. - Sample 3: Array
[2 7 1]. When , the second element is , and the third element is . Since , a pattern exists.
Constraints
Time limit for each test case is second, and memory limit is KiB.