You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"payload":{"allShortcutsEnabled":false,"fileTree":{"src/pathSum":{"items":[{"name":"pathSum.II.cpp","path":"src/pathSum/pathSum.II.cpp","contentType":"file"},{"name":"pathSum.cpp","path":"src/pathSum/pathSum.cpp","contentType":"file"}],"totalCount":2},"src":{"items":[{"name":"3Sum","path":"src/3Sum","contentType":"directory"},{"name":"3SumClosest","path":"src/3SumClosest","contentType":"directory"},{"name":"4Sum","path":"src/4Sum","contentType":"directory"},{"name":"LRUCache","path":"src/LRUCache","contentType":"directory"},{"name":"addBinary","path":"src/addBinary","contentType":"directory"},{"name":"addTwoNumbers","path":"src/addTwoNumbers","contentType":"directory"},{"name":"anagrams","path":"src/anagrams","contentType":"directory"},{"name":"balancedBinaryTree","path":"src/balancedBinaryTree","contentType":"directory"},{"name":"bestTimeToBuyAndSellStock","path":"src/bestTimeToBuyAndSellStock","contentType":"directory"},{"name":"binaryTreeInorderTraversal","path":"src/binaryTreeInorderTraversal","contentType":"directory"},{"name":"binaryTreeLevelOrderTraversal","path":"src/binaryTreeLevelOrderTraversal","contentType":"directory"},{"name":"binaryTreeMaximumPathSum","path":"src/binaryTreeMaximumPathSum","contentType":"directory"},{"name":"binaryTreePostorderTraversal","path":"src/binaryTreePostorderTraversal","contentType":"directory"},{"name":"binaryTreePreorderTraversal","path":"src/binaryTreePreorderTraversal","contentType":"directory"},{"name":"binaryTreeZigzagLevelOrderTraversal","path":"src/binaryTreeZigzagLevelOrderTraversal","contentType":"directory"},{"name":"candy","path":"src/candy","contentType":"directory"},{"name":"climbStairs","path":"src/climbStairs","contentType":"directory"},{"name":"cloneGraph","path":"src/cloneGraph","contentType":"directory"},{"name":"combinationSum","path":"src/combinationSum","contentType":"directory"},{"name":"combinations","path":"src/combinations","contentType":"directory"},{"name":"constructBinaryTreeFromInorderAndPostorderTraversal","path":"src/constructBinaryTreeFromInorderAndPostorderTraversal","contentType":"directory"},{"name":"constructBinaryTreeFromPreorderAndInorderTraversal","path":"src/constructBinaryTreeFromPreorderAndInorderTraversal","contentType":"directory"},{"name":"containerWithMostWater","path":"src/containerWithMostWater","contentType":"directory"},{"name":"convertSortedArrayToBinarySearchTree","path":"src/convertSortedArrayToBinarySearchTree","contentType":"directory"},{"name":"convertSortedListToBinarySearchTree","path":"src/convertSortedListToBinarySearchTree","contentType":"directory"},{"name":"copyListWithRandomPointer","path":"src/copyListWithRandomPointer","contentType":"directory"},{"name":"countAndSay","path":"src/countAndSay","contentType":"directory"},{"name":"decodeWays","path":"src/decodeWays","contentType":"directory"},{"name":"distinctSubsequences","path":"src/distinctSubsequences","contentType":"directory"},{"name":"divideTwoInt","path":"src/divideTwoInt","contentType":"directory"},{"name":"editDistance","path":"src/editDistance","contentType":"directory"},{"name":"evaluateReversePolishNotation","path":"src/evaluateReversePolishNotation","contentType":"directory"},{"name":"findMinimumInRotatedSortedArray","path":"src/findMinimumInRotatedSortedArray","contentType":"directory"},{"name":"firstMissingPositive","path":"src/firstMissingPositive","contentType":"directory"},{"name":"flattenBinaryTreeToLinkedList","path":"src/flattenBinaryTreeToLinkedList","contentType":"directory"},{"name":"gasStation","path":"src/gasStation","contentType":"directory"},{"name":"generateParentheses","path":"src/generateParentheses","contentType":"directory"},{"name":"grayCode","path":"src/grayCode","contentType":"directory"},{"name":"insertInterval","path":"src/insertInterval","contentType":"directory"},{"name":"insertionSortList","path":"src/insertionSortList","contentType":"directory"},{"name":"integerToRoman","path":"src/integerToRoman","contentType":"directory"},{"name":"interleavingString","path":"src/interleavingString","contentType":"directory"},{"name":"jumpGame","path":"src/jumpGame","contentType":"directory"},{"name":"largestRectangleInHistogram","path":"src/largestRectangleInHistogram","contentType":"directory"},{"name":"lengthOfLastWord","path":"src/lengthOfLastWord","contentType":"directory"},{"name":"letterCombinationsOfAPhoneNumber","path":"src/letterCombinationsOfAPhoneNumber","contentType":"directory"},{"name":"linkedListCycle","path":"src/linkedListCycle","contentType":"directory"},{"name":"longestCommonPrefix","path":"src/longestCommonPrefix","contentType":"directory"},{"name":"longestConsecutiveSequence","path":"src/longestConsecutiveSequence","contentType":"directory"},{"name":"longestPalindromicSubstring","path":"src/longestPalindromicSubstring","contentType":"directory"},{"name":"longestSubstringWithoutRepeatingCharacters","path":"src/longestSubstringWithoutRepeatingCharacters","contentType":"directory"},{"name":"longestValidParentheses","path":"src/longestValidParentheses","contentType":"directory"},{"name":"maxPointsOnALine","path":"src/maxPointsOnALine","contentType":"directory"},{"name":"maximalRectangle","path":"src/maximalRectangle","contentType":"directory"},{"name":"maximumDepthOfBinaryTree","path":"src/maximumDepthOfBinaryTree","contentType":"directory"},{"name":"maximumProductSubarray","path":"src/maximumProductSubarray","contentType":"directory"},{"name":"maximumSubArray","path":"src/maximumSubArray","contentType":"directory"},{"name":"medianOfTwoSortedArrays","path":"src/medianOfTwoSortedArrays","contentType":"directory"},{"name":"mergeIntervals","path":"src/mergeIntervals","contentType":"directory"},{"name":"mergeKSortedLists","path":"src/mergeKSortedLists","contentType":"directory"},{"name":"mergeTwoSortedArray","path":"src/mergeTwoSortedArray","contentType":"directory"},{"name":"mergeTwoSortedList","path":"src/mergeTwoSortedList","contentType":"directory"},{"name":"minimumDepthOfBinaryTree","path":"src/minimumDepthOfBinaryTree","contentType":"directory"},{"name":"minimumPathSum","path":"src/minimumPathSum","contentType":"directory"},{"name":"minimumWindowSubstring","path":"src/minimumWindowSubstring","contentType":"directory"},{"name":"multiplyStrings","path":"src/multiplyStrings","contentType":"directory"},{"name":"nQueens","path":"src/nQueens","contentType":"directory"},{"name":"nextPermutation","path":"src/nextPermutation","contentType":"directory"},{"name":"palindromeNumber","path":"src/palindromeNumber","contentType":"directory"},{"name":"palindromePartitioning","path":"src/palindromePartitioning","contentType":"directory"},{"name":"partitionList","path":"src/partitionList","contentType":"directory"},{"name":"pascalTriangle","path":"src/pascalTriangle","contentType":"directory"},{"name":"pathSum","path":"src/pathSum","contentType":"directory"},{"name":"permutationSequence","path":"src/permutationSequence","contentType":"directory"},{"name":"permutations","path":"src/permutations","contentType":"directory"},{"name":"plusOne","path":"src/plusOne","contentType":"directory"},{"name":"populatingNextRightPointersInEachNode","path":"src/populatingNextRightPointersInEachNode","contentType":"directory"},{"name":"pow","path":"src/pow","contentType":"directory"},{"name":"recoverBinarySearchTree","path":"src/recoverBinarySearchTree","contentType":"directory"},{"name":"regularExpressionMatching","path":"src/regularExpressionMatching","contentType":"directory"},{"name":"removeDuplicatesFromSortedArray","path":"src/removeDuplicatesFromSortedArray","contentType":"directory"},{"name":"removeDuplicatesFromSortedList","path":"src/removeDuplicatesFromSortedList","contentType":"directory"},{"name":"removeElement","path":"src/removeElement","contentType":"directory"},{"name":"removeNthNodeFromEndOfList","path":"src/removeNthNodeFromEndOfList","contentType":"directory"},{"name":"reorderList","path":"src/reorderList","contentType":"directory"},{"name":"restoreIPAddresses","path":"src/restoreIPAddresses","contentType":"directory"},{"name":"reverseInteger","path":"src/reverseInteger","contentType":"directory"},{"name":"reverseLinkedList","path":"src/reverseLinkedList","contentType":"directory"},{"name":"reverseNodesInKGroup","path":"src/reverseNodesInKGroup","contentType":"directory"},{"name":"reverseWordsInAString","path":"src/reverseWordsInAString","contentType":"directory"},{"name":"romanToInteger","path":"src/romanToInteger","contentType":"directory"},{"name":"rotateImage","path":"src/rotateImage","contentType":"directory"},{"name":"rotateList","path":"src/rotateList","contentType":"directory"},{"name":"sameTree","path":"src/sameTree","contentType":"directory"},{"name":"scrambleString","path":"src/scrambleString","contentType":"directory"},{"name":"search2DMatrix","path":"src/search2DMatrix","contentType":"directory"},{"name":"searchForRange","path":"src/searchForRange","contentType":"directory"},{"name":"searchInRotatedSortedArray","path":"src/searchInRotatedSortedArray","contentType":"directory"},{"name":"searchInsertPosition","path":"src/searchInsertPosition","contentType":"directory"},{"name":"setMatrixZeroes","path":"src/setMatrixZeroes","contentType":"directory"},{"name":"simplifyPath","path":"src/simplifyPath","contentType":"directory"},{"name":"singleNumber","path":"src/singleNumber","contentType":"directory"},{"name":"sortColors","path":"src/sortColors","contentType":"directory"},{"name":"sortList","path":"src/sortList","contentType":"directory"},{"name":"spiralMatrix","path":"src/spiralMatrix","contentType":"directory"},{"name":"sqrt","path":"src/sqrt","contentType":"directory"},{"name":"strStr","path":"src/strStr","contentType":"directory"},{"name":"stringToIntegerAtoi","path":"src/stringToIntegerAtoi","contentType":"directory"},{"name":"subsets","path":"src/subsets","contentType":"directory"},{"name":"substringWithConcatenationOfAllWords","path":"src/substringWithConcatenationOfAllWords","contentType":"directory"},{"name":"sudokuSolver","path":"src/sudokuSolver","contentType":"directory"},{"name":"sumRootToLeafNumber","path":"src/sumRootToLeafNumber","contentType":"directory"},{"name":"surroundedRegions","path":"src/surroundedRegions","contentType":"directory"},{"name":"swapNodesInPairs","path":"src/swapNodesInPairs","contentType":"directory"},{"name":"symmetricTree","path":"src/symmetricTree","contentType":"directory"},{"name":"textJustification","path":"src/textJustification","contentType":"directory"},{"name":"trappingRainWater","path":"src/trappingRainWater","contentType":"directory"},{"name":"triangle","path":"src/triangle","contentType":"directory"},{"name":"twoSum","path":"src/twoSum","contentType":"directory"},{"name":"uniqueBinarySearchTrees","path":"src/uniqueBinarySearchTrees","contentType":"directory"},{"name":"uniquePaths","path":"src/uniquePaths","contentType":"directory"},{"name":"validNumber","path":"src/validNumber","contentType":"directory"},{"name":"validPalindrome","path":"src/validPalindrome","contentType":"directory"},{"name":"validParentheses","path":"src/validParentheses","contentType":"directory"},{"name":"validSudoku","path":"src/validSudoku","contentType":"directory"},{"name":"validateBinarySearchTree","path":"src/validateBinarySearchTree","contentType":"directory"},{"name":"wildcardMatching","path":"src/wildcardMatching","contentType":"directory"},{"name":"wordBreak","path":"src/wordBreak","contentType":"directory"},{"name":"wordLadder","path":"src/wordLadder","contentType":"directory"},{"name":"wordSearch","path":"src/wordSearch","contentType":"directory"},{"name":"zigZagConversion","path":"src/zigZagConversion","contentType":"directory"}],"totalCount":131},"":{"items":[{"name":"src","path":"src","contentType":"directory"},{"name":"README.md","path":"README.md","contentType":"file"}],"totalCount":2}},"fileTreeProcessingTime":7.7600050000000005,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":25851146,"defaultBranch":"master","name":"leetcode-9","ownerLogin":"nkhuyu","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2014-10-28T03:17:23.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/2619292?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1614071453.890709","canEdit":false,"refType":"branch","currentOid":"540738b55bfdc49eba05ed8dce45631e3758ba1b"},"path":"src/pathSum/pathSum.cpp","currentUser":null,"blob":{"rawLines":["// Source : https://oj.leetcode.com/problems/path-sum/","// Author : Hao Chen","// Date : 2014-06-22","","/********************************************************************************** ","* ","* Given a binary tree and a sum, determine if the tree has a root-to-leaf path ","* such that adding up all the values along the path equals the given sum.","* ","* For example:","* Given the below binary tree and sum = 22,","* ","* 5","* / \\","* 4 8","* / / \\","* 11 13 4","* / \\ \\","* 7 2 1","* ","* return true, as there exist a root-to-leaf path 5-\u003e4-\u003e11-\u003e2 which sum is 22.","* ","**********************************************************************************/","","#include \u003ctime.h\u003e","","/**"," * Definition for binary tree"," * struct TreeNode {"," * int val;"," * TreeNode *left;"," * TreeNode *right;"," * TreeNode(int x) : val(x), left(NULL), right(NULL) {}"," * };"," */","class Solution {","public:"," Solution(){"," srand(time(NULL));"," }"," bool hasPathSum(TreeNode *root, int sum) {"," if (random()%2){"," return hasPathSum1(root, sum); "," }"," return hasPathSum2(root, sum);"," }"," "," bool hasPathSum1(TreeNode *root, int sum) {"," if (root==NULL) return false;"," vector\u003cTreeNode*\u003e v;"," v.push_back(root);"," while(v.size()\u003e0){"," TreeNode* node = v.back();"," v.pop_back();"," if (node-\u003eleft==NULL \u0026\u0026 node-\u003eright==NULL){"," if (node-\u003eval == sum){"," return true;"," }"," }"," if (node-\u003eleft){"," node-\u003eleft-\u003eval += node-\u003eval;"," v.push_back(node-\u003eleft);"," }"," if (node-\u003eright){"," node-\u003eright-\u003eval += node-\u003eval;"," v.push_back(node-\u003eright);"," }"," }"," return false;"," "," }"," "," bool hasPathSum2(TreeNode *root, int sum) {"," "," if (root==NULL) return false;"," "," if (root-\u003eleft==NULL \u0026\u0026 root-\u003eright==NULL ){"," return (root-\u003eval==sum);"," }"," "," if (root-\u003eleft){"," root-\u003eleft-\u003eval += root-\u003eval;"," if (hasPathSum2(root-\u003eleft, sum)){"," return true;"," }"," }"," "," if (root-\u003eright){"," root-\u003eright-\u003eval += root-\u003eval;"," if (hasPathSum2(root-\u003eright, sum)){"," return true;"," }"," }"," "," return false;"," }","","};"],"stylingDirectives":[[[0,54,"pl-c"],[0,2,"pl-c"]],[[0,20,"pl-c"],[0,2,"pl-c"]],[[0,22,"pl-c"],[0,2,"pl-c"]],[],[[0,84,"pl-c"],[0,2,"pl-c"]],[[0,2,"pl-c"]],[[0,79,"pl-c"]],[[0,73,"pl-c"]],[[0,2,"pl-c"]],[[0,14,"pl-c"]],[[0,43,"pl-c"]],[[0,2,"pl-c"]],[[0,17,"pl-c"]],[[0,18,"pl-c"]],[[0,19,"pl-c"]],[[0,20,"pl-c"]],[[0,21,"pl-c"]],[[0,22,"pl-c"]],[[0,23,"pl-c"]],[[0,2,"pl-c"]],[[0,78,"pl-c"]],[[0,16,"pl-c"]],[[0,83,"pl-c"],[81,83,"pl-c"]],[],[[1,8,"pl-k"],[9,17,"pl-s"],[9,10,"pl-pds"],[16,17,"pl-pds"]],[],[[0,3,"pl-c"],[0,2,"pl-c"]],[[0,29,"pl-c"]],[[0,20,"pl-c"]],[[0,15,"pl-c"]],[[0,22,"pl-c"]],[[0,23,"pl-c"]],[[0,59,"pl-c"]],[[0,5,"pl-c"]],[[0,3,"pl-c"],[1,3,"pl-c"]],[[0,5,"pl-k"],[6,14,"pl-en"]],[[0,7,"pl-k"]],[[4,12,"pl-en"]],[[8,13,"pl-c1"],[14,18,"pl-c1"],[19,23,"pl-c1"]],[],[[4,8,"pl-k"],[9,19,"pl-en"],[36,39,"pl-k"]],[[8,10,"pl-k"],[12,18,"pl-c1"],[21,22,"pl-c1"]],[[12,18,"pl-k"],[19,30,"pl-c1"]],[],[[8,14,"pl-k"],[15,26,"pl-c1"]],[],[],[[4,8,"pl-k"],[9,20,"pl-en"],[37,40,"pl-k"]],[[8,10,"pl-k"],[18,22,"pl-c1"],[24,30,"pl-k"],[31,36,"pl-c1"]],[],[[10,19,"pl-c1"]],[[8,13,"pl-k"],[16,20,"pl-c1"],[23,24,"pl-c1"]],[[31,35,"pl-c1"]],[[14,22,"pl-c1"]],[[12,14,"pl-k"],[22,26,"pl-smi"],[28,32,"pl-c1"],[42,47,"pl-smi"],[49,53,"pl-c1"]],[[16,18,"pl-k"],[26,29,"pl-smi"]],[[20,26,"pl-k"],[27,31,"pl-c1"]],[],[],[[12,14,"pl-k"],[22,26,"pl-smi"]],[[22,26,"pl-smi"],[28,31,"pl-smi"],[41,44,"pl-smi"]],[[18,27,"pl-c1"],[34,38,"pl-smi"]],[],[[12,14,"pl-k"],[22,27,"pl-smi"]],[[22,27,"pl-smi"],[29,32,"pl-smi"],[42,45,"pl-smi"]],[[18,27,"pl-c1"],[34,39,"pl-smi"]],[],[],[[8,14,"pl-k"],[15,20,"pl-c1"]],[],[],[],[[4,8,"pl-k"],[9,20,"pl-en"],[37,40,"pl-k"]],[],[[8,10,"pl-k"],[18,22,"pl-c1"],[24,30,"pl-k"],[31,36,"pl-c1"]],[],[[8,10,"pl-k"],[18,22,"pl-smi"],[24,28,"pl-c1"],[38,43,"pl-smi"],[45,49,"pl-c1"]],[[12,18,"pl-k"],[26,29,"pl-smi"]],[],[],[[8,10,"pl-k"],[18,22,"pl-smi"]],[[18,22,"pl-smi"],[24,27,"pl-smi"],[37,40,"pl-smi"]],[[12,14,"pl-k"],[16,27,"pl-c1"],[34,38,"pl-smi"]],[[16,22,"pl-k"],[23,27,"pl-c1"]],[],[],[],[[8,10,"pl-k"],[18,23,"pl-smi"]],[[18,23,"pl-smi"],[25,28,"pl-smi"],[38,41,"pl-smi"]],[[12,14,"pl-k"],[16,27,"pl-c1"],[34,39,"pl-smi"]],[[16,22,"pl-k"],[23,27,"pl-c1"]],[],[],[],[[8,14,"pl-k"],[15,20,"pl-c1"]],[],[],[]],"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/nkhuyu/leetcode-9/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"pathSum.cpp","displayUrl":"https://github.com/nkhuyu/leetcode-9/blob/master/src/pathSum/pathSum.cpp?raw=true","headerInfo":{"blobSize":"2.45 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"f019dee","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fnkhuyu%2Fleetcode-9%2Fblob%2Fmaster%2Fsrc%2FpathSum%2FpathSum.cpp","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"98","truncatedSloc":"86"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"C++","languageID":43,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/nkhuyu/leetcode-9/blob/master/src/pathSum/pathSum.cpp","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/nkhuyu/leetcode-9/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/nkhuyu/leetcode-9/raw/refs/heads/master/src/pathSum/pathSum.cpp","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/nkhuyu/leetcode-9/branches":{"post":"cRtLc3N-5zgZ4aQEvs-Kr-nKxMhmB7HPthBq5U8AN-sfHDy_rJ2KvfLLE66kZYlv24mA8kDnUvVyqYbr2EktAA"},"/repos/preferences":{"post":"OXRS0Awug09pyixbTQpoiS6l9ChA1_YrB0GJrNSui5WusnUtmE_RBsuoVwWb3arhfNfR8HV1VqniwgnF6Wu8KA"}}},"title":"leetcode-9/src/pathSum/pathSum.cpp at master · nkhuyu/leetcode-9","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-1b17b3e7786a.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}