Inglizcha: Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).
Specifically, ans is the concatenation of two nums arrays.
Return the array ans.
O'zbekcha: n uzunlikga ega butun sonli array berilgan, siz ans 2n uzunlikga ega array yaratishingiz kerak qaysiki ans[i] == nums[i] va ans[i + n] == nums[i] ni qanoatlantirishi kerak 0 <= i < n.
ans bu ikkita nums ni birikmasi.
ans arrayni natija sifatida qaytaring.
Misol 1
$ Input: nums=[1,2,1]$ Output: [1,2,1,1,2,1]$ Explanation: The array ans is formed as follows:
- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]- ans = [1,2,1,1,2,1]
Misol 2
$ Input: nums=[1,3,2,1]$ Output: [1,3,2,1,1,3,2,1]$ Explanation: The array ans is formed as follows:
- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]- ans = [1,3,2,1,1,3,2,1]
Bizga nums ni uzunligi kerak bunga biz n o'zgaruvchisini yaratib nums ni uzunligini tenglab olamiz va 0 dan n gacha sikl ochib nums ga nums[i] qo'shib boramiz. Oxirida nums ni qaytarib yuboramiz.
# Author: Abdulaminkhon Khaydarov# Date: 02/11/22 # Problem URL: https://leetcode.com/problems/concatenation-of-array/fromtypingimportListclassSolution:defgetConcatenation(self,nums:List[int])->List[int]:n=len(nums)foriinrange(n):nums.append(nums[i])returnnumsif__name__=='__main__':solution=Solution()# Example 1print(solution.getConcatenation([1,2,1])==[1,2,1,1,2,1])# Example 2print(solution.getConcatenation([1,3,2,1])==[1,3,2,1,1,3,2,1])
# Author: Abdulaminkhon Khaydarov# Date: 02/11/22 # Problem URL: https://leetcode.com/problems/concatenation-of-array/fromtypingimportListclassSolution:defgetConcatenation(self,nums:List[int])->List[int]:returnnums*2if__name__=='__main__':solution=Solution()# Example 1print(solution.getConcatenation([1,2,1])==[1,2,1,1,2,1])# Example 2print(solution.getConcatenation([1,3,2,1])==[1,3,2,1,1,3,2,1])
# Author: Abdulaminkhon Khaydarov# Date: 02/11/22 # Problem URL: https://leetcode.com/problems/concatenation-of-array/fromtypingimportListclassSolution:defgetConcatenation(self,nums:List[int])->List[int]:returnnums+numsif__name__=='__main__':solution=Solution()# Example 1print(solution.getConcatenation([1,2,1])==[1,2,1,1,2,1])# Example 2print(solution.getConcatenation([1,3,2,1])==[1,3,2,1,1,3,2,1])