当前位置: 首页 > news >正文

网站建设费用会计入什么费用123浏览器下载

网站建设费用会计入什么费用,123浏览器下载,pc端网站开发技术,宣城市建设监督管理局网站【C#刷题】| 作者 / Edison Zhou这是EdisonTalk的第292篇原创内容我们来用之前学到的数据结构知识来刷《剑指Offer》的一些核心题目#xff08;精选了其中30道题目#xff09;#xff0c;希望对你有帮助#xff01;本文题目为#xff1a;二叉树中和为某一值的路径。1题目介… 【C#刷题】| 作者 / Edison Zhou这是EdisonTalk的第292篇原创内容我们来用之前学到的数据结构知识来刷《剑指Offer》的一些核心题目精选了其中30道题目希望对你有帮助本文题目为二叉树中和为某一值的路径。1题目介绍题目输入一棵二叉树和一个整数打印出二叉树中结点值的和为输入整数的所有路径。从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。例如输入下图中二叉树和整数22则打印出两条路径第一条路径包含结点10、12第二条路径包含结点10、5和7。二叉树结点的自定义代码如下public class BinaryTreeNode {public int Data { get; set; }public BinaryTreeNode leftChild { get; set; }public BinaryTreeNode rightChild { get; set; }public BinaryTreeNode(int data){this.Data data;}public BinaryTreeNode(int data, BinaryTreeNode left, BinaryTreeNode right){this.Data data;this.leftChild left;this.rightChild right;} } 2解题思路与实现核心思路首先通过下图了解遍历上图中的二叉树的过程通过上图可以总结出规律1当用前序遍历的方式访问到某一结点时我们把该结点添加到路径上并累加该结点的值。2如果该结点为叶结点并且路径中结点值的和刚好等于输入的整数则当前的路径符合要求我们把它打印出来。如果当前结点不是叶结点则继续访问它的子结点。3当前结点访问结束后递归函数将自动回到它的父结点。这里要注意的是在函数退出之前要在路径上删除当前结点并减去当前结点的值以确保返回父结点时路径刚好是从根结点到父结点的路径。代码实现public static void FindPath(BinaryTreeNode root, int expectedSum) {if (root null){return;}int currentSum 0;Listint path new Listint();FindPath(root, expectedSum, path, ref currentSum); }private static void FindPath(BinaryTreeNode root, int expectedSum, Listint path, ref int currentSum) {currentSum root.Data;path.Add(root.Data);// 如果是叶结点并且路径上结点的和等于输入的值// 打印出这条路径bool isLeaf root.leftChild null root.rightChild null;if (isLeaf currentSum expectedSum){foreach (int data in path){Console.Write({0}\t, data);}Console.WriteLine();}// 如果不是叶结点则遍历它的子结点if (root.leftChild ! null){FindPath(root.leftChild, expectedSum, path, ref currentSum);}if (root.rightChild ! null){FindPath(root.rightChild, expectedSum, path, ref currentSum);}// 在返回到父结点之前在路径上删除当前结点// 并在currentSum中减去当前结点的值path.Remove(root.Data);currentSum - root.Data; } 3单元测试测试辅助方法private static void TestPortal(string testName, BinaryTreeNode root, int expectedSum) {if (!string.IsNullOrEmpty(testName)){Console.WriteLine({0} begins:, testName);}FindPath(root, expectedSum);Console.WriteLine(); }private static void SetSubTreeNode(BinaryTreeNode root, BinaryTreeNode lChild, BinaryTreeNode rChild) {if (root null){return;}root.leftChild lChild;root.rightChild rChild; }private static void ClearUpTreeNode(BinaryTreeNode root) {if (root ! null){BinaryTreeNode left root.leftChild;BinaryTreeNode right root.rightChild;root null;ClearUpTreeNode(left);ClearUpTreeNode(right);} } 单元测试用例// 10 // / \ // 5 12 // /\ // 4 7 // 有两条路径上的结点和为22 public static void Test1() {BinaryTreeNode node10 new BinaryTreeNode(10);BinaryTreeNode node5 new BinaryTreeNode(5);BinaryTreeNode node12 new BinaryTreeNode(12);BinaryTreeNode node4 new BinaryTreeNode(4);BinaryTreeNode node7 new BinaryTreeNode(7);SetSubTreeNode(node10, node5, node12);SetSubTreeNode(node5, node4, node7);Console.WriteLine(Two paths should be found in Test1.);TestPortal(Test1, node10, 22);ClearUpTreeNode(node10); }// 10 // / \ // 5 12 // /\ // 4 7 // 没有路径上的结点和为15 public static void Test2() {BinaryTreeNode node10 new BinaryTreeNode(10);BinaryTreeNode node5 new BinaryTreeNode(5);BinaryTreeNode node12 new BinaryTreeNode(12);BinaryTreeNode node4 new BinaryTreeNode(4);BinaryTreeNode node7 new BinaryTreeNode(7);SetSubTreeNode(node10, node5, node12);SetSubTreeNode(node5, node4, node7);Console.WriteLine(No paths should be found in Test2.);TestPortal(Test2, node10, 15);ClearUpTreeNode(node10); }// 5 // / // 4 // / // 3 // / // 2 // / // 1 // 有一条路径上面的结点和为15 public static void Test3() {BinaryTreeNode node5 new BinaryTreeNode(5);BinaryTreeNode node4 new BinaryTreeNode(4);BinaryTreeNode node3 new BinaryTreeNode(3);BinaryTreeNode node2 new BinaryTreeNode(2);BinaryTreeNode node1 new BinaryTreeNode(1);node5.leftChild node4;node4.leftChild node3;node3.leftChild node2;node2.leftChild node1;Console.WriteLine(One path should be found in Test3.);TestPortal(Test3, node5, 15);ClearUpTreeNode(node5); }// 1 // \ // 2 // \ // 3 // \ // 4 // \ // 5 // 没有路径上面的结点和为16 public static void Test4() {BinaryTreeNode node1 new BinaryTreeNode(1);BinaryTreeNode node2 new BinaryTreeNode(2);BinaryTreeNode node3 new BinaryTreeNode(3);BinaryTreeNode node4 new BinaryTreeNode(4);BinaryTreeNode node5 new BinaryTreeNode(5);node1.leftChild node2;node2.leftChild node3;node3.leftChild node4;node4.leftChild node5;Console.WriteLine(No paths should be found in Test4.);TestPortal(Test4, node1, 16);ClearUpTreeNode(node1); }// 树中只有1个结点 public static void Test5() {BinaryTreeNode node1 new BinaryTreeNode(1);Console.WriteLine(One paths should be found in Test5.);TestPortal(Test5, node1, 1);ClearUpTreeNode(node1); }// 树中没有结点 public static void Test6() {Console.WriteLine(No paths should be found in Test6.);TestPortal(Test6, null, 0); } 测试结果测试的结果情况如下图Ref参考资料何海涛《剑指Offer》后台回复剑指offer即可获得pdf下载链接哟????扫码关注EdisonTalk设为星标不再失联往期推文合集2020年上半年推文合集成都新鲜坑位喜鹊生活招聘.NET开发
http://www.zqtcl.cn/news/949488/

相关文章:

  • 没有网站怎么做cpa成都百度推广公司地址
  • 龙湖地产 网站建设高端上海网站设计公司
  • 触屏手机网站模板装修设计软件排名
  • 怎么做盗文网站郑州建设教育培训中心
  • 网站安全解决方案嵌入式软件工程师培训
  • 怎么做一种网站为别人宣传网站界面切片做程序
  • 麻涌网站建设河北网站建设联系方式
  • 建设银行官方网站打不开啊寮步仿做网站
  • 一个人可做几次网站备案峰峰网站建设
  • 怎么盗号网站怎么做北京高端网站设计外包公司
  • 著名的淘宝客网站wordpress博客内容预览
  • 成都网站seo公司甘肃网站建设推广
  • 做网站加班网站项目意义
  • 在虚拟机中如何做二级域名网站个人网站做哪种能赚钱
  • 贵州建设水利厅考试网站wordpress主查询翻页
  • 网站优化网络推广seo天津建设工程信息网几点更新
  • 兰州网站seo技术厂家比较实用的h5网页建设网站
  • 怎样让自己做的网站被百度收录动漫制作软件
  • 西安网站制作哪家公司好怎么向企业推销网站建设
  • 电子商务网站建设新闻深圳坂田网站设计公司有哪些
  • 上海电子商城网站制作wordpress循环该分类子分类
  • 茶山做网站教育网站建设计划书
  • 成品门户网站源码免费海外网络加速器免费
  • 企业网站怎么建设公司深圳企业招聘信息最新招聘信息
  • 天津网站经营性备案下载网站上的表格 怎么做
  • 胶州企业网站设计十大互联网营销公司
  • 视频解析wordpresswordpress 优化版本
  • 柳州网站建设哪家便宜广东省建设厅三库一平台
  • 云南城市建设官方网站wordpress和织梦哪个好
  • 国外企业招聘网站专门做外贸的网站有哪些