fork download
  1. /**
  2.  * Definition for a binary tree node.
  3.  * struct TreeNode {
  4.  * int val;
  5.  * TreeNode *left;
  6.  * TreeNode *right;
  7.  * TreeNode() : val(0), left(nullptr), right(nullptr) {}
  8.  * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  9.  * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  10.  * };
  11.  */
  12. class Solution {
  13. private:
  14. set<int> se;
  15. void DFS(TreeNode* node){
  16. if(!node) return;
  17. se.insert(node->val);
  18. DFS(node->left); // Only follows leftmost path!
  19. }
  20. public:
  21. int kthSmallest(TreeNode* root, int k) {
  22. DFS(root);
  23. k--;
  24. return *se.begin()+k; // Wrong! Adds k to first element
  25. }
  26. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:14:9: error: ‘set’ does not name a type
         set<int> se;
         ^~~
prog.cpp:15:18: error: ‘TreeNode’ has not been declared
         void DFS(TreeNode* node){
                  ^~~~~~~~
prog.cpp:21:25: error: ‘TreeNode’ has not been declared
         int kthSmallest(TreeNode* root, int k) {
                         ^~~~~~~~
prog.cpp: In member function ‘void Solution::DFS(int*)’:
prog.cpp:17:13: error: ‘se’ was not declared in this scope
             se.insert(node->val);
             ^~
prog.cpp:17:29: error: request for member ‘val’ in ‘* node’, which is of non-class type ‘int’
             se.insert(node->val);
                             ^~~
prog.cpp:18:23: error: request for member ‘left’ in ‘* node’, which is of non-class type ‘int’
             DFS(node->left);  // Only follows leftmost path!
                       ^~~~
prog.cpp: In member function ‘int Solution::kthSmallest(int*, int)’:
prog.cpp:24:21: error: ‘se’ was not declared in this scope
             return *se.begin()+k;  // Wrong! Adds k to first element
                     ^~
stdout
Standard output is empty