Skip to content

Commit 865ec64

Browse files
authored
feat: add php solution to lc problem: No.2068 (#991)
1 parent 7c8e2ef commit 865ec64

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ func checkAlmostEquivalent(word1 string, word2 string) bool {
140140
}
141141
```
142142

143+
### **PHP**
144+
145+
```php
146+
class Solution {
147+
/**
148+
* @param String $word1
149+
* @param String $word2
150+
* @return Boolean
151+
*/
152+
function checkAlmostEquivalent($word1, $word2) {
153+
for ($i = 0; $i < strlen($word1); $i++) {
154+
$hashtable[$word1[$i]] += 1;
155+
$hashtable[$word2[$i]] -= 1;
156+
}
157+
$keys = array_keys($hashtable);
158+
for ($j = 0; $j < count($keys); $j++) {
159+
if (abs($hashtable[$keys[$j]]) > 3) return false;
160+
}
161+
return true;
162+
}
163+
}
164+
```
165+
143166
### **...**
144167

145168
```

solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ func checkAlmostEquivalent(word1 string, word2 string) bool {
131131
}
132132
```
133133

134+
### **PHP**
135+
136+
```php
137+
class Solution {
138+
/**
139+
* @param String $word1
140+
* @param String $word2
141+
* @return Boolean
142+
*/
143+
function checkAlmostEquivalent($word1, $word2) {
144+
for ($i = 0; $i < strlen($word1); $i++) {
145+
$hashtable[$word1[$i]] += 1;
146+
$hashtable[$word2[$i]] -= 1;
147+
}
148+
$keys = array_keys($hashtable);
149+
for ($j = 0; $j < count($keys); $j++) {
150+
if (abs($hashtable[$keys[$j]]) > 3) return false;
151+
}
152+
return true;
153+
}
154+
}
155+
```
156+
134157
### **...**
135158

136159
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
/**
3+
* @param String $word1
4+
* @param String $word2
5+
* @return Boolean
6+
*/
7+
function checkAlmostEquivalent($word1, $word2) {
8+
for ($i = 0; $i < strlen($word1); $i++) {
9+
$hashtable[$word1[$i]] += 1;
10+
$hashtable[$word2[$i]] -= 1;
11+
}
12+
$keys = array_keys($hashtable);
13+
for ($j = 0; $j < count($keys); $j++) {
14+
if (abs($hashtable[$keys[$j]]) > 3) return false;
15+
}
16+
return true;
17+
}
18+
}

0 commit comments

Comments
 (0)