11,808
社区成员




/**
* 计算最长递增的区间长度
* @param arr 无序的数组
* @return
*/
public static int func(int[] arr){
//定义变量len:长度
int len = 1;
int maxLen = 0;
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i]<=arr[i+1]){
len++;
}else {
if (maxLen < len) {
maxLen = len;
}
len = 1;
}
}
return maxLen;
}
function longestIncreasingInterval(arr) {
if (arr.length <= 1) {
return arr.length;
}
let maxLength = 1;
let length = 1;
for (let i = 1; i < arr.length; i++) {
if (arr[i] > arr[i - 1]) {
length++;
} else {
maxLength = Math.max(maxLength, length);
length = 1;
}
}
maxLength = Math.max(maxLength, length);
return maxLength;
}
const arr = [5, 2, 3, 8, 1, 9];
const result = longestIncreasingInterval(arr);
console.log(result);
class Solution:
def init(self,lst):
self.lst = list(lst)
self.lenth = 0
def method(self):
for i in range(0,len(self.lst) - 1):
if self.lst[i] < self.lst[i+1]:
self.lenth += 1
def show(self):
print(self.lenth)
if name == 'main':
lst = map(int,input('enter:').split(' '))
s1 = Solution(list(lst))
s1.method()
s1.show()