202. Happy Number
Write an algorithm to determine if a number n 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.
Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
Those numbers for which this process ends in 1 are happy.
Return true if n is a happy number, and false if not.
Example 1:
1 | Input: n = 19 |
Example 2:
1 | Input: n = 2 |
350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.
Example 1:
1 | Input: nums1 = [1,2,2,1], nums2 = [2,2] |
Example 2:
1 | Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] |
Note:
1 | Each element in the result should appear as many times as it shows in both arrays. |
米其林一星明福台菜海鮮
閱讀刻意練習
原子習慣再搭配刻意練習就是堅持每天進步一點點