Merge branch 'master' into patch06

This commit is contained in:
程序员Carl
2022-06-02 08:37:02 +08:00
committed by GitHub
85 changed files with 2774 additions and 277 deletions

View File

@@ -385,6 +385,7 @@ bool isHappy(int n){
return bHappy;
}
```
Scala:
```scala
object Solution {
@@ -416,6 +417,28 @@ object Solution {
}
sum
}
C#
```csharp
public class Solution {
private int getSum(int n) {
int sum = 0;
//每位数的换算
while (n > 0) {
sum += (n % 10) * (n % 10);
n /= 10;
}
return sum;
}
public bool IsHappy(int n) {
HashSet <int> set = new HashSet<int>();
while(n != 1 && !set.Contains(n)) { //判断避免循环
set.Add(n);
n = getSum(n);
}
return n == 1;
}
}
```
-----------------------