做项目时经常遇到树状层级数据.从各个层级数据的转换查询等.场景如行业类别的多层级,行政区层级,检查项类别层级等等. 数据结构如 Id Name ParentId #region area树状节点的转化 public List<Area> ConvertToLeafChildAreas(List<int> areaIds) { var allAreas = GetNewAreas().ToList(); List<Area> leafChildren = new Lis
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 二分递归转换 Hide Tags Tree Depth-first Search /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode
PS: 程序为cpp代码,最重要理解操作. 方法一: n进制方法,也可以解决转换为其他进制问题. /*将整数转化为二进制的string 输出*/ string convert(int num) { string res = ""; if (num == 0) return "0"; int val = num; num = abs(num); while (num) { res.insert(0, to_string(num % 2)); num /= 2; } i