Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 876 Bytes

풀이_LC136.md

File metadata and controls

32 lines (23 loc) · 876 Bytes

🌕 136. Single Number

  • Date : 2021.06.27(일)
  • Time : 10분

Problem

  • Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
  • You must implement a solution with a linear runtime complexity and use only constant extra space.

Constraints

  • 1 <= nums.length <= 3 * 10^4
  • -3 * 10^4 <= nums[i] <= 3 * 10^4
  • Each element in the array appears twice except for one element which appears only once.

Example

  • Input: nums = [2,2,1]
  • Output: 1

풀이

    def singleNumber(self, nums: list[int]) -> int:
        for i in nums:
            if nums.count(i) == 1 :
                return i

: 중복되지 않는 유일한 값을 구하는 문제. 중복되지 않는다 라는 것은 그 배열에 1개만 존재한다는 뜻이기 때문에 count를 이용해 간단히 풀었다.