Created
June 29, 2021 14:18
-
-
Save dongwooklee96/e0322dc55b1bd43f13a813cb93506b4b to your computer and use it in GitHub Desktop.
problem 1.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| ## 문제 : 1.4 | |
| - 정렬된 배열의 요소들을 중복 없이, 단 1번씩만 가질 수 있도록 주어진 배열을 그대로 수정하고, | |
| 수정된 배열의 새로운 길이를 반환하라. | |
| """ | |
| from typing import List | |
| def solve(nums: List[int]) -> List[int]: | |
| if len(nums) < 0: | |
| return 0 | |
| curr = nums[0] | |
| cnt = 1 | |
| for i in range(1, len(nums)): | |
| if curr != nums[i]: | |
| curr = nums[i] | |
| nums[cnt] = curr | |
| cnt += 1 | |
| return cnt | |
| if __name__ == "__main__": | |
| nums = list(map(int, input().split())) | |
| print(solve(nums)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment