Skip to content

Commit 014acf8

Browse files
add 179
1 parent f5da60e commit 014acf8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ LeetCode
168168
|0172|[Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes/) | c | [c++](./src/0172-Factorial-Trailing-Zeroes/0172.cpp) |[python](./src/0172-Factorial-Trailing-Zeroes/0172.py)|||Easy|
169169
|0173|[Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/) | c | [c++](./src/0173-Binary-Search-Tree-Iterator/0173.cpp) |[python](./src/0173-Binary-Search-Tree-Iterator/0173.py)|||Medium|
170170
|0174|[Dungeon Game](https://leetcode.com/problems/dungeon-game/) | c | [c++](./src/0174-Dungeon-Game/0174.cpp) |[python](./src/0174-Dungeon-Game/0174.py)|||Hard|
171+
|0179|[Largest Number](https://leetcode.com/problems/largest-number/) | c | [c++](./src/0179-Largest-Number/0179.cpp) |[python](./src/0179-Largest-Number/0179.py)|||Medium|
171172
|0187|[Repeated-DNA-Sequences](https://leetcode.com/problems/repeated-dna-sequences/) | c | [c++](./src/0187-Repeated-DNA-Sequences/0187.cpp) |[python](./src/0187-Repeated-DNA-Sequences/0187.py)|||Medium|
172173
|0188|[Best Time to Buy and Sell Stock IV](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/) | c | [c++](./src/0188-Best-Time-to-Buy-and-Sell-Stock-IV/0188.cpp) |[python](./src/0188-Best-Time-to-Buy-and-Sell-Stock-IV/0188.py)|||Hard|
173174
|0189|[Rotate Array](https://leetcode.com/problems/rotate-array/) | c | [c++](./src/0189-Rotate-Array/0189.cpp) |[python](./src/0189-Rotate-Array/0189.py)|||Easy|

src/0179-Largest-Number/0179.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
2+
class Solution
3+
{
4+
public:
5+
string largestNumber(vector<int>& nums)
6+
{
7+
sort(nums.begin(), nums.end(), [](const int a, const int b) {
8+
string as = to_string(a), bs = to_string(b);
9+
return as + bs > bs + as;
10+
});
11+
12+
if (nums[0] == 0) return "0";
13+
string res;
14+
for (int j = 0; j < nums.size(); ++j)
15+
{
16+
res += to_string(nums[j]);
17+
}
18+
return res;
19+
}
20+
};

src/0179-Largest-Number/0179.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class compare(str):
2+
def __lt__(x, y):
3+
return x+y > y+x
4+
5+
class Solution:
6+
def largestNumber(self, nums: List[int]) -> str:
7+
if not nums:
8+
return ""
9+
nums = sorted(list(map(str, nums)), key=compare)
10+
return '0' if nums[0] == '0' else "".join(nums)

0 commit comments

Comments
 (0)