题目考察的知识点是:
本题主要考察知识点是哈希表。
题目解答方法的文字分析:
通过循环去获取最大连接数,然后用三元运算符获取结果。
本题解析所用的编程语言:
java语言。
完整且正确的编程代码:
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param ids int整型一维数组 * @param n int整型 * @return int整型 */ public int longestConsecutive (int[] ids, int n) { // write code here int maxLength = 0; int currentLength = 1; for (int i = 1; i < n; i++) { if (ids[i] > ids[i - 1]) { currentLength++; } else { maxLength = maxLength > currentLength ? maxLength : currentLength; currentLength = 1; } } return maxLength > currentLength ? maxLength : currentLength; } }