Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b11695

Browse files
committed
Add solution 179.
1 parent 7f570e8 commit 1b11695

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
3+
function cmp($str1, $str2) {
4+
$s1 = $str1 . $str2;
5+
$s2 = $str2 . $str1;
6+
return strcmp($s2, $s1);
7+
}
8+
9+
/**
10+
* @param Integer[] $nums
11+
* @return String
12+
*/
13+
function largestNumber($nums) {
14+
$strs = array_fill(0, count($nums), "");
15+
for ($i=0; $i<count($nums); $i++) {
16+
$strs[$i] = "" . $nums[$i];
17+
}
18+
19+
usort($strs, 'self::cmp');
20+
21+
if ($strs[0] == "0") {
22+
return "0";
23+
}
24+
25+
$sb = "";
26+
foreach ($strs as $str) {
27+
$sb .= $str;
28+
}
29+
30+
return $sb;
31+
}
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /