[OJ.leetcode] binary-tree-zigzag-level-order-traversal
https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ iven a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ] /* BFS를 응용해서, 자료..
더보기
[OJ.leetcode] maximum-subarray
https://oj.leetcode.com/problems/maximum-subarray/ Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the largest sum = 6. class Solution { public: int maxSubArray(int A[], int n) { if(n == 1) return A[0]; int maxSum = A[0]; int currSum = 0; for(int i..
더보기