what is wrong?

is this function right?

when i put (1,0,0,1,1) it return true.....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bool palindrome_2(vector<int>vec,int begin,int end){
    
       if( vec[begin] != vec[end]  ) {
        
        return false;
    }
    //return result;
    
    //cout << endl;
    //cout << vec[begin] <<" and " << vec[end] <<endl;
    palindrome_2(vec,begin+1,end-1);
    
    return true;
    
    
    
}
alter the code as follows:


return palindrome_2(vec,begin+1,end-1);


instead of

palindrome_2(vec,begin+1,end-1);

return true;

Last edited on
no it does no work

try 17 or other numbers
You need to stop call palindrome_2 if begin >= end.
Topic archived. No new replies allowed.