Line 29: Char 37: runtime error: member access within misaligned address 0xbebebebebebebebe for type ‘TreeNode’, which requires 8 byte alignment (solution.cpp) 0xbebebebebebebebe: note: pointer points here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:38:37
刷题的时候遇到的,主要问题是访问空间无信息,错误代码
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> vec_st;
if(root==NULL) return{};
queue<TreeNode*> st;
st.push(root);
while(!st.empty()){
vector<int> vec;
int len = st.size();
for(int i=0;i<len;i--)
{
TreeNode* node = st.front();
st.pop();
vec.push_back(node->val);
if(node->left) {
st.push(node->left);
}
if(node->right){
st.push(node->right);
}
}
vec_st.push_back(vec);
}
return vec_st;
}
修改
for(int i=0;i<len;i++)
|