Cần giúp về Challenge adjacentElementsProduct trên Codefight

Đề: Như vậy
Còn Mã:

int adjacentElementsProduct(std::vector<int> inputArray) {
    int result=inputArray[0]*inputArray[1];
    int N=sizeof(inputArray)/sizeof(int);
    
    int val;
    for (int i=1;i<N-1;++i){
        val=inputArray[i]*inputArray[i+1];
        if (val>result) result=val;
    }
    
    return result;

}

Cho mình hỏi là còn thiếu sót j ko vậy mà mình ko wa 1 hidden test của nó.

Tràn số. Đảm bảo luôn.

Với lại prototype nên có const và tham chiếu.

3 Likes

Tràn số là sao vậy bạn?

Mà tràn dữ liệu ở chỗ nào vậy b. mình thấy nó nằm trong dữ liệu mà.

Dùng sizeof để tính số lượng phần tử là sai. N=inputArray.size();

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?