Skip to content

Commit 341d3b8

Browse files
committed
Adding solution
1 parent 842844b commit 341d3b8

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

leetcode/1470_shuffle_the_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://leetcode.com/problems/shuffle-the-array/
2+
3+
from typing import List
4+
5+
class Solution:
6+
def shuffle(self, nums: List[int], n: int) -> List[int]:
7+
shuffled_arr = list()
8+
i = 0
9+
while i < n:
10+
shuffled_arr.extend((nums[i], nums[i+1]))
11+
i += 1
12+
13+
return shuffled_arr
14+
15+
# Note:
16+
# 1. Extend better than multiple appens
17+
# 2. List creation more expensive than tuple
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://leetcode.com/problems/running-sum-of-1d-array/
2+
3+
from typing import List
4+
5+
class Solution:
6+
def runningSum(self, nums: List[int]) -> List[int]:
7+
return [sum(nums[:i+1]) for i in range(len(nums))]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
2+
3+
from typing import List
4+
5+
class Solution:
6+
def finalValueAfterOperations(self, operations: List[str]) -> int:
7+
x = 0
8+
for opr in operations:
9+
if "--" in opr:
10+
x -= 1
11+
else:
12+
x += 1
13+
return x

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