File tree 3 files changed +61
-0
lines changed
solution/0400-0499/0451.Sort Characters By Frequency
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,28 @@ impl Solution {
178
178
}
179
179
```
180
180
181
+ ### ** PHP**
182
+
183
+ ``` php
184
+ class Solution {
185
+ /**
186
+ * @param String $s
187
+ * @return String
188
+ */
189
+ function frequencySort($s) {
190
+ for ($i = 0; $i < strlen($s); $i++) {
191
+ $hashtable[$s[$i]] += 1;
192
+ }
193
+ arsort($hashtable);
194
+ $keys = array_keys($hashtable);
195
+ for ($j = 0; $j < count($keys); $j++) {
196
+ $rs = $rs.str_repeat($keys[$j], $hashtable[$keys[$j]]);
197
+ }
198
+ return $rs;
199
+ }
200
+ };
201
+ ```
202
+
181
203
### ** ...**
182
204
183
205
```
Original file line number Diff line number Diff line change @@ -162,6 +162,28 @@ impl Solution {
162
162
}
163
163
```
164
164
165
+ ### ** PHP**
166
+
167
+ ``` php
168
+ class Solution {
169
+ /**
170
+ * @param String $s
171
+ * @return String
172
+ */
173
+ function frequencySort($s) {
174
+ for ($i = 0; $i < strlen($s); $i++) {
175
+ $hashtable[$s[$i]] += 1;
176
+ }
177
+ arsort($hashtable);
178
+ $keys = array_keys($hashtable);
179
+ for ($j = 0; $j < count($keys); $j++) {
180
+ $rs = $rs.str_repeat($keys[$j], $hashtable[$keys[$j]]);
181
+ }
182
+ return $rs;
183
+ }
184
+ };
185
+ ```
186
+
165
187
### ** ...**
166
188
167
189
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param String $s
4
+ * @return String
5
+ */
6
+ function frequencySort ($s ) {
7
+ for ($i = 0 ; $i < strlen ($s ); $i ++ ) {
8
+ $hashtable [$s [$i ]] += 1 ;
9
+ }
10
+ arsort ($hashtable );
11
+ $keys = array_keys ($hashtable );
12
+ for ($j = 0 ; $j < count ($keys ); $j ++ ) {
13
+ $rs = $rs . str_repeat ($keys [$j ], $hashtable [$keys [$j ]]);
14
+ }
15
+ return $rs ;
16
+ }
17
+ };
You can’t perform that action at this time.
0 commit comments