Merge branch 'master' into patch06
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
```
|
||||
-----------------------
|
||||
|
||||
Reference in New Issue
Block a user