更新 0202.快乐数 排版格式修复

This commit is contained in:
jinbudaily
2023-07-19 14:34:27 +08:00
parent 19dfa98e4f
commit 764b3e9e51

View File

@ -28,7 +28,7 @@
6^2 + 8^2 = 100 6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1 1^2 + 0^2 + 0^2 = 1
# 思路 ## 思路
这道题目看上去貌似一道数学问题,其实并不是! 这道题目看上去貌似一道数学问题,其实并不是!
@ -80,10 +80,10 @@ public:
# 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
class Solution { class Solution {
public boolean isHappy(int n) { public boolean isHappy(int n) {
@ -107,8 +107,9 @@ class Solution {
} }
``` ```
Python ### Python
(版本一)使用集合 (版本一)使用集合
```python ```python
class Solution: class Solution:
def isHappy(self, n: int) -> bool: def isHappy(self, n: int) -> bool:
@ -131,7 +132,7 @@ class Solution:
n, r = divmod(n, 10) n, r = divmod(n, 10)
new_num += r ** 2 new_num += r ** 2
return new_num return new_num
``` ```
(版本二)使用集合 (版本二)使用集合
```python ```python
class Solution: class Solution:
@ -146,7 +147,7 @@ class Solution:
if new_num==1: return True if new_num==1: return True
else: n = new_num else: n = new_num
return False return False
``` ```
(版本三)使用数组 (版本三)使用数组
```python ```python
class Solution: class Solution:
@ -161,7 +162,7 @@ class Solution:
if new_num==1: return True if new_num==1: return True
else: n = new_num else: n = new_num
return False return False
``` ```
(版本四)使用快慢指针 (版本四)使用快慢指针
```python ```python
class Solution: class Solution:
@ -180,7 +181,7 @@ class Solution:
n, r = divmod(n, 10) n, r = divmod(n, 10)
new_num += r ** 2 new_num += r ** 2
return new_num return new_num
``` ```
(版本五)使用集合+精简 (版本五)使用集合+精简
```python ```python
class Solution: class Solution:
@ -192,7 +193,7 @@ class Solution:
return False return False
seen.add(n) seen.add(n)
return True return True
``` ```
(版本六)使用数组+精简 (版本六)使用数组+精简
```python ```python
class Solution: class Solution:
@ -204,8 +205,9 @@ class Solution:
return False return False
seen.append(n) seen.append(n)
return True return True
``` ```
Go ### Go
```go ```go
func isHappy(n int) bool { func isHappy(n int) bool {
m := make(map[int]bool) m := make(map[int]bool)
@ -225,7 +227,7 @@ func getSum(n int) int {
} }
``` ```
javaScript: ### JavaScript:
```js ```js
var isHappy = function (n) { var isHappy = function (n) {
@ -303,7 +305,7 @@ var isHappy = function(n) {
}; };
``` ```
TypeScript: ### TypeScript:
```typescript ```typescript
function isHappy(n: number): boolean { function isHappy(n: number): boolean {
@ -322,7 +324,7 @@ function isHappy(n: number): boolean {
}; };
``` ```
Swift ### Swift
```swift ```swift
// number 每个位置上的数字的平方和 // number 每个位置上的数字的平方和
@ -355,7 +357,8 @@ func isHappy(_ n: Int) -> Bool {
} }
``` ```
PHP: ### PHP:
```php ```php
class Solution { class Solution {
/** /**
@ -386,7 +389,8 @@ class Solution {
} }
``` ```
Rust: ### Rust:
```Rust ```Rust
use std::collections::HashSet; use std::collections::HashSet;
impl Solution { impl Solution {
@ -416,7 +420,8 @@ impl Solution {
} }
``` ```
C: ### C:
```C ```C
typedef struct HashNodeTag { typedef struct HashNodeTag {
int key; /* num */ int key; /* num */
@ -473,8 +478,8 @@ object Solution {
} }
``` ```
### C#
C#
```csharp ```csharp
public class Solution { public class Solution {
private int getSum(int n) { private int getSum(int n) {
@ -500,3 +505,4 @@ public class Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>