Runtime Error but can work on my local computer.


  • 0
    L

    Can anybody help to tell me what's wrong with my code? It can work on my local computer, but got runtime error after submit.

    class Solution {
    public:
    int removeElement(int A[], int n, int elem) {
    int l = 0;
    int r = n - 1;

        while (l < r) {
            while (l <= r && A[l] != elem) {
                l++;
            }
            while (l <= r && A[r] == elem) {
                r--;
            }
            cout << "l:" << l << ", r:" << r << endl;
            A[l++] = A[r--];
        }
        
        return l - 1;
    }
    

    };

    Last executed input: [0,2,2,0,3,1,4,4,3,4], 8


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.