[JAVA] easiest iterative solution using stack
\n\n# Code\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     Tre
\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    public int kthSmallest(TreeNode root, int k) {\n       Stack<TreeNode> st = new Stack<>();\n       TreeNode p = root;\n       int count = 0;\n\n       while(!st.isEmpty() || p != null) {\n           if(p != null) {\n           st.push(p);\n           p = p.left;\n           }\n           else {\n               TreeNode node = st.pop();\n               if(++ count == k) return node.val;\n               p = node.right;\n           }\n       } \n       return Integer.MIN_VALUE;\n    }\n}\n```\n# PLEASE UPVOTE IF IT WAS HELPFULL
['Java']