반응형
    
    
    
  https://leetcode.com/problems/build-array-from-permutation/description/
간단 구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
정답 변수 ans를 선언합니다.
📔 풀이과정
nums의 원소를 순회하며 ans에 nums[nums[i]]값을 넣어줍니다.
📔 정답 출력 | 반환
ans를 반환합니다.
📕 Code
📔 Python3
class Solution(object):
    def buildArray(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        ans = []
        for i in range(len(nums)):
            ans.append(nums[nums[i]])
        return ans*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
| (Python3) - LeetCode (easy) 1935. Maximum Number of Words You Can Type (0) | 2024.09.24 | 
|---|---|
| (Python3) - LeetCode (easy) 1929. Concatenation of Array (0) | 2024.09.23 | 
| (C++) - LeetCode (easy) 539. Minimum Time Difference (1) | 2024.09.16 | 
| (C++) - LeetCode (easy) 1903. Largest Odd Number in String (0) | 2024.09.16 | 
| (C++) - LeetCode (easy) 1897. Redistribute Characters to Make All Strings Equal (1) | 2024.09.13 |