#include "BinaryTreeProblems.h"
#include<stack>
int countDegreeOneNodes(TreeNode* rootss) {
int ans=0;
auto root=rootss;
std::stack<TreeNode*>s;
while (!s.empty() or root)
{
while(root){
s.push(root);
root=root->left;
}
if (!s.empty())
{
auto top=s.top();
s.pop();
if (top->left==nullptr and top->right==nullptr)
{
if(top!=rootss) ans+=1;
}
root=root->right;
}
}
if(rootss->left==nullptr xor rootss->right==nullptr) ans+=1;
return ans;
}