2273。删除字谜后查找结果数组(Leetcode 问题)

问题描述 投票:0回答:0

在我的代码行中,它显示索引 -97 出站。为什么会这样显示?我的代码哪里出了问题?

我不明白为什么会显示。我的代码或我的逻辑有什么问题?

class Solution {
public:
vector<string> removeAnagrams(vector<string>& words) {

        bool ans = true;
        for(int i=1;i<words.size();i++){
            int temp[26]={0};
            for(int j=0;j<words[i].size();j++){
                int x = words[i][j];
                int y = words[i-1][j];
              int check=x-97;
              int check1 = y-97;
           
                temp[check]++;  // at this place it is showing error 
                temp[check1]--;  //  at this place it is showing error
            
            }
            for(int k=0;k<26;k++){
                if(temp[k])  ans =false;
            }
            if(ans==true){
                words.erase(words.begin()+i);
                i--;
            }
    
        }
        return words;;
    }

};
c++ string anagram
© www.soinside.com 2019 - 2024. All rights reserved.