C#: Inorder traverse tree using IEnumerable
Intuition\nUse DFS and traverse BST inorder. \n\n# Approach\nThe idea is to use one of key features of IEnumerable, namely Lazy Evaluation. The app should NOT e
# Intuition\nUse DFS and traverse BST inorder. \n\n# Approach\nThe idea is to use one of key features of IEnumerable, namely Lazy Evaluation. The app should NOT enumerate through all collection and only traverses first K element(s). This should improve performance in contrast with approaches that uses List or Array structures.\n\nThis solution beats 99% (89 ms) execution time. Memory usage 42.8 MB (beats 10%).\n\n# Complexity\n- Time complexity: O(k)\n\n- Space complexity: O(k) but I\'m not sure.\n\n# Code\n```\npublic class Solution {\n    public int KthSmallest(TreeNode root, int k) {\n\n        return Inorder(root).Skip(k-1).Take(1).First();\n\n        IEnumerable<int> Inorder(TreeNode node){\n            if (node is not null){\n                foreach(var n in Inorder(node.left)){\n                    yield return n;\n                }\n                // Trace.WriteLine(node.val); // Output: 1, 2, .. k\n                yield return node.val;\n                foreach(var n in Inorder(node.right)){\n                    yield return n;\n                }\n            }\n\n\n        }\n    }\n}\n```
['C#']