牛客题霸-算法篇
数组中的最长连续子序列
相似的企业真题
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 256M,其他语言512M
热度指数:5261
本题知识点:
并查集
数组
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
给定无序数组arr,返回其中最长的连续序列的长度(要求值连续,位置可以不连续,例如 3,4,5,6为连续的自然数)
示例1
输入
复制
[100,4,200,1,3,2]
[100,4,200,1,3,2]
返回值
复制
4
4
示例2
输入
复制
[1,1,1]
[1,1,1]
返回值
复制
1
1
备注:
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
import java.util.*; public class Solution { /** * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ public int MLS (int[] arr) { // write code here } }
class Solution { public: /** * max increasing subsequence * @param arr int整型vector the array * @return int整型 */ int MLS(vector
& arr) { // write code here } };
# # max increasing subsequence # @param arr int整型一维数组 the array # @return int整型 # class Solution: def MLS(self , arr ): # write code here
/** * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ function MLS( arr ) { // write code here } module.exports = { MLS : MLS };
# # max increasing subsequence # @param arr int整型一维数组 the array # @return int整型 # class Solution: def MLS(self , arr ): # write code here
package main /** * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ func MLS( arr []int ) int { // write code here }
/** * max increasing subsequence * @param arr int整型一维数组 the array * @param arrLen int arr数组长度 * @return int整型 */ int MLS(int* arr, int arrLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # max increasing subsequence # @param arr int整型一维数组 the array # @return int整型 # class Solution def MLS(arr) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ def MLS(arr: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ fun MLS(arr: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ public int MLS (int[] arr) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ export function MLS(arr: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ func MLS ( _ arr: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * max increasing subsequence * @param arr int整型一维数组 the array * @return int整型 */ pub fn MLS(&self, arr: Vec
) -> i32 { // write code here } }
[100,4,200,1,3,2]
4
[1,1,1]
1