Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- dacon
- 더현대서울 맛집
- Kaggle
- 금융문자분석경진대회
- Baekjoon
- 프로그래머스
- 편스토랑 우승상품
- Git
- 코로나19
- programmers
- 프로그래머스 파이썬
- SW Expert Academy
- 파이썬
- ubuntu
- 데이콘
- PYTHON
- hackerrank
- Docker
- 우분투
- 백준
- gs25
- 캐치카페
- Real or Not? NLP with Disaster Tweets
- AI 경진대회
- 맥북
- ChatGPT
- 편스토랑
- github
- 자연어처리
- leetcode
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1470. Shuffle the Array (Python) 본문
728x90
반응형
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
Return the array in the form [x1,y1,x2,y2,...,xn,yn].
Example 1:
Input: nums = [2,5,1,3,4,7], n = 3
Output: [2,3,5,4,1,7]
Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].
Example 2:
Input: nums = [1,2,3,4,4,3,2,1], n = 4
Output: [1,4,2,3,3,2,4,1]
Example 3:
Input: nums = [1,1,2,2], n = 2
Output: [1,2,1,2]
Constraints:
- 1 <= n <= 500
- nums.length == 2n
- 1 <= nums[i] <= 10^3
Solution
class Solution:
def shuffle(self, nums: List[int], n: int) -> List[int]:
answer = []
for i in range(len(nums) // 2):
answer.append(nums[i])
answer.append(nums[i+n])
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 442. Find All Duplicates in an Array (Python) (0) | 2020.10.13 |
---|---|
[leetCode] 504. Base 7 (Python) (0) | 2020.10.12 |
[leetCode] 896. Monotonic Array (Python) (0) | 2020.10.09 |
[leetCode] 258. Add Digits (Python) (0) | 2020.10.08 |
[leetCode] 1089. Duplicate Zeros (Python) (0) | 2020.10.07 |
Comments