Lunski's Clutter

This is a place to put my clutters, no matter you like it or not, welcome here.

0%

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
2
3
4
5
6
7
Input: n = 19
Output: true
Explanation:
1ˆ2 + 9ˆ2 = 82
8ˆ2 + 2ˆ2 = 68
6ˆ2 + 8ˆ2 = 100
1ˆ2 + 0ˆ2 + 02 = 1

Example 2:

1
2
Input: n = 2
Output: false
Read more »

Given two arrays, write a function to compute their intersection.

Example 1:

1
2
Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]

Example 2:

1
2
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [4,9]

Note:

1
2
Each element in the result should appear as many times as it shows in both arrays.
The result can be in any order.
Read more »

原子習慣再搭配刻意練習就是堅持每天進步一點點

Read more »