nonzeroBitCount) 알고리즘 문제 풀이 시 유용하게 사용할 수 있는 swift 프로퍼티

w0308h 2022년 12월 31일 PM 08:58 18 0
w0308h Profile Image Level 9

nonzeroBitCount 사용 시 2진 수 변환 후 0의 개수를 반환해준다.
알고리즘 문제 풀이 시 유용!

let n = 78 //1001110
print(n.nonzeroBitCount) //4

참고: [Apple Document](https://developer.apple.com/documentation/swift/int/nonzerobitcount)

댓글