Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01b94c2

Browse files
committed
Create concatenation of array.py
1 parent bdf23a0 commit 01b94c2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎arrays_hasing/concatenation of array.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Problem 1: Concatenation of Array
2+
# Link: https://neetcode.io/problems/concatenation-of-array?list=neetcode250
3+
4+
# You are given an integer array nums of length n. Create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).
5+
# Specifically, ans is the concatenation of two nums arrays.
6+
# Return the array ans.
7+
# Example:
8+
# Input: nums = [1,4,1,2]
9+
# Output: [1,4,1,2,1,4,1,2]
10+
11+
nums = [1,4,1,2]
12+
n = len(nums)
13+
14+
ans = []
15+
16+
def concat_array(nums,x):
17+
for i in range(0,x):
18+
for j in nums:
19+
ans.append(j)
20+
21+
print(ans)
22+
23+
concat_array(nums,2)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /