257. Binary Tree Paths

Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. 1 2 3 4 5 6 7 8 9 Example 1: Input: root = [1,2,3,null,5] Output: ["1->2->5","1->3"] Example 2: Input: root = [1] Output: ["1"] Constraints: The number of nodes in the tree is in the range [1, 100]. -100 <= Node.val <= 100 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 /** * Definition for a binary tree node....

<span title='2021-11-22 00:00:00 +0000 UTC'>November 22, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

346. Moving Average from Data Stream

Given two sparse vectors, compute their dot product. Implement class SparseVector: SparseVector(nums) Initializes the object with the vector nums dotProduct(vec) Compute the dot product between the instance of SparseVector and vec A sparse vector is a vector that has mostly zero values, you should store the sparse vector efficiently and compute the dot product between two SparseVector. Follow up: What if only one of the vectors is sparse? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Example 1: Input: nums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0] Output: 8 Explanation: v1 = SparseVector(nums1) , v2 = SparseVector(nums2) v1....

<span title='2021-11-19 00:00:00 +0000 UTC'>November 19, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx