Developing Code for Binary Tree Maximum Path Sum
Creating a Branch and Cloning a Repository
Developers need to develop code for new requirements based on the develop-dev branch.
- Open the req-demo project and choose Code > Repo from the navigation pane to access CodeArts Repo.
- Click the repo-demo repository.
- Open the local Git Bash, and run the following command to clone the develop-dev branch to the local PC:
git clone -b Branch name https://example.com
In the preceding command, Branch name indicates the name of the branch to be cloned, and https://example.com indicates the HTTPS address of the code repository.
If the following information is displayed, the develop-dev branch of the code repository repo-demo has been successfully cloned to the local PC:$ git clone -b develop-dev https://test.com/bb5f2eb7ded44e0bbc0ff4bd3d1d244c/repo-demo.git Cloning into 'repo-demo'... remote: Enumerating objects: 36, done. remote: Counting objects: 100% (36/36), done. remote: Compressing objects: 100% (30/30), done. remote: Total 36 (delta 0), reused 36 (delta 0), pack-reused 0 (from 0) Unpacking objects: 100% (36/36), 301.74 KiB | 1.23 MiB/s, done.
Developing Code
- In the upper left corner of CodeArts Agent IDE, choose to open the created code repository repo-demo.
- In the input box of CodeArts Agent, enter the following information and click
: A path in a binary tree is defined as a node sequence, where an edge exists between every two adjacent nodes in the sequence. A node can appear only once in a path. The path must contain at least one node and does not necessarily pass through the root node. The path sum is the sum of the values of all nodes in the path. Based on this project, provide the root node of a binary tree, and return the maximum path sum. If you have any questions, feel free to ask me.
- After the code is generated, enter the following information, compile and run the verification script using Java and javac, and click
. Write a verification script and use Java and javac to compile and run it.
- After the script is generated, confirm the file path and file name. For example, the generated file is run-tests.ps1 and stored in repo-demo/java-agent. After confirming the generated file, choose Terminal > New Terminal in the navigation pane and run the following command:
powershell -ExecutionPolicy Bypass -File java-agent\run-tests.ps1Note: Replace java-agent\run-tests.ps1 with the actual script path and name generated in your project.
If the following information is displayed, the code can run properly:========================================== Maximum path sum in a binary tree - test and verification ========================================== [PASS] example1 [1,2,3] => 6 [PASS] example2 [-10,9,20,null,null,15,7] => 42 [PASS] allNegative [-1,-2,-3] => -1 [PASS] leftSkewedTree [5,4,null,3,null,2] => 14 [PASS] negativeBranchesIgnored [2,-1,-2] => 2 [PASS] complexTree => 1 =========================================== Results: 9 passed, 0 failed =========================================== All tests are passed.
The actual output prevails.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot