<commit_before>// https://leetcode.com/problems/binary-tree-paths/

struct TreeNode {
  int val;
  TreeNode* left;
  TreeNode* right;
  TreeNode(int x) : val(x), left(0), right(0) {}
};

#include <string>
#include <vector>

class Solution {
public:
  std::vector<std::string> binaryTreePaths(TreeNode* root) {
    std::vector<std::string> v;
    constructPath(root, "", v);
    return v;
  }
private:
  void constructPath(TreeNode* root, std::string s, std::vector<std::string>& v) {
    if (!root) return;
    if (!root->left && !root->right) v.push_back(s + std::to_string(root->val));

    constructPath(root->left, s + std::to_string(root->val) + "->", v);
    constructPath(root->right, s + std::to_string(root->val) + "->", v);
  }
};<commit_msg>:new: binary tree paths<commit_after>// https://leetcode.com/problems/binary-tree-paths/

/*
  Given a binary tree, return all root-to-leaf paths.

  For example, given the following binary tree:

     1
   /   \
  2     3
   \
    5

  All root-to-leaf paths are:
  ["1->2->5", "1->3"]
*/

#include <vector>
#include <string>

using std::vector;
using std::string;

struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  explicit TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
  vector<string> binaryTreePaths(TreeNode* root) {
    if (!root) return {};
    
    vector<string> paths;
    traverse(root, "", paths);
    return paths;
  }
private:
  void traverse(TreeNode* t, string const& s, vector<string>& paths) {
    if (!t->left && !t->right) {
      return paths.push_back(s + std::to_string(t->val));
    }
    if (t->left) traverse(t->left, s + std::to_string(t->val) + "->", paths);
    if (t->right) traverse(t->right, s + std::to_string(t->val) + "->", paths);
  }
};
{'fraction_non_alphanumeric': 0.18924972004479285, 'fraction_numerical': 0.006159014557670772, 'mean_word_length': 3.5240506329113925, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3674733', 'n_tokens_mistral': 658, 'n_tokens_neox': 651, 'n_words': 149}