samedi 19 août 2023

(Pallindrome checker) [LEETCODE problem] I know I'm commiting some minor mistake but i don't know what it is

class Solution {
public:
    bool isPalindrome(string s) {
        getline(cin,s);
                bool answer;
                vector<int>l;
                vector<int>r;
                for(auto i=0;i<s.size();i++){
                    char c = s[i];
                    l.push_back(c);
                }
                for(auto i=s.size()-1;i<s.size();i--){
                    char a = s[i];
                    r.push_back(a);
                }
                for(auto i=0;i++;){
                    if(l[i]==r[i]) answer = true;
                    if(l[i]!=r[i]) answer = false;
                }
                return answer;
    }
};

I was expecting it to work fine but i think i am commiting some logical error while writing bool datatype.

the output in vscode is just blank output.

This program has cleared 2 testcases out of 3 in leetcode compiler.

Aucun commentaire:

Enregistrer un commentaire