-
1342. Number of Steps to Reduce a Number to Zero릿코드(LEETCODE) 2020. 2. 13. 11:29반응형
https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero
Source
class Solution { public: int numberOfSteps (int num) { int sol = 1; while(num !=1){ int cand = num & 1; if(cand) { cand -= 1; sol++; } num /= 2; sol++; } return sol; } };
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
136. Single Number (0) 2020.02.13 268. Missing Number (0) 2020.02.13 70. Climbing Stairs (0) 2020.02.12 746. Min Cost Climbing Stairs (0) 2020.02.12 242. Valid Anagram (0) 2020.02.12