【easy】202. Happy Number】的更多相关文章

happy number Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the proc…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 [LeetCode] 题目地址:https://leetcode.com/problems/happy-number/ Total Accepted: 36352 Total Submissions: 109782 Difficulty: Easy 题目描述 Write an algorithm to determine if a…
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the…
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1 Input: [3,0,1] Output: 2 Example 2 Input: [9,6,4,2,3,5,7,0,1] Output: 8 用异或的办法: class Solution { public: int missingNumber…
class Solution { public: bool isUgly(int num) { ) return false; ) return true; && num % == ) num /= ; && num % == ) num /= ; && num % == ) num /= ; ; } }; 所谓丑数,是指质因子只能是2,3,5中的.1认为也是丑数.…
181. Flip Bits[easy] Determine the number of bits required to flip if you want to convert integer n to integer m. Notice Both n and m are 32-bit integers. Example Given n = 31 (11111), m = 14 (01110), return 2. 解法一: class Solution { public: /** *@par…
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should support the following operations:add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum…
88. Merge Sorted Array[easy] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.…
605. Can Place Flowers[easy] Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represe…
485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number…