Skip to content

Commit a9b790c

Browse files
refactor 339
1 parent 42fe117 commit a9b790c

File tree

1 file changed

+16
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+16
-0
lines changed

src/main/java/com/fishercoder/solutions/_339.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
import java.util.List;
66

7+
/**
8+
* 339. Nested List Weight Sum
9+
*
10+
* Given a nested list of integers, return the sum of all integers in the list weighted by their depth.
11+
* Each element is either an integer, or a list -- whose elements may also be integers or other lists.
12+
*
13+
* Example 1:
14+
* Input: [[1,1],2,[1,1]]
15+
* Output: 10
16+
* Explanation: Four 1's at depth 2, one 2 at depth 1.
17+
*
18+
* Example 2:
19+
* Input: [1,[4,[6]]]
20+
* Output: 27
21+
* Explanation: One 1 at depth 1, one 4 at depth 2, and one 6 at depth 3; 1 + 4*2 + 6*3 = 27.
22+
* */
723
public class _339 {
824
public static class Solution1 {
925
private int sum = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy