[Rust] O(h+k) minimalist iterative solution with explanations. (0ms, faster than 100%.)
rust\n// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n//   pub val: i32,\n//   pub left: Option<Rc<RefCell<
```rust\n// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n//   pub val: i32,\n//   pub left: Option<Rc<RefCell<TreeNode>>>,\n//   pub right: Option<Rc<RefCell<TreeNode>>>,\n// }\n// \n// impl TreeNode {\n//   #[inline]\n//   pub fn new(val: i32) -> Self {\n//     TreeNode {\n//       val,\n//       left: None,\n//       right: None\n//     }\n//   }\n// }\n\nuse std::rc::Rc;\nuse std::cell::RefCell;\n\nimpl Solution {\n    pub fn kth_smallest(mut node_opt: Option<Rc<RefCell<TreeNode>>>, mut k: i32) -> i32 {\n        let mut nodes = Vec::new();\n        while node_opt.is_some() || !nodes.is_empty() {\n            // Go to the smallest (i.e. left-most) node:\n            while let Some(node) = node_opt {\n                nodes.push(node.clone());\n                node_opt = node.borrow().left.clone();\n            }\n            if let Some(node) = nodes.pop() { // nodes contains Rc<RefCell<TreeNode>>s but pop returns Option<T>.\n                // Check the current smallest node:\n                k -= 1;\n                if k == 0 {\n                    return node.borrow().val;\n                }\n                // Check the right sub-tree:\n                node_opt = node.borrow().right.clone();    \n            }\n        }\n        unreachable!();\n    }\n}\n```
['Iterator', 'Rust']