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 fdccbe0

Browse files
add: leetcode 179
1 parent 9ca4a70 commit fdccbe0

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

‎LeetCode/179.Largest Number.cpp‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
15+
string largestNumber(vector<int> &nums)
16+
{
17+
vector<string> s(nums.size(),"");
18+
string ans="";
19+
20+
for(int i=0;i<nums.size();i++){
21+
s[i]=to_string(nums[i]);
22+
}
23+
sort(s.begin(),s.end(),[](const string &a, const string &b){
24+
return a+b>b+a;
25+
});
26+
if(s[0]=="0"){
27+
ans="0";
28+
}
29+
else{
30+
for(auto x:s){
31+
ans+=x;
32+
}
33+
}
34+
return ans;
35+
}
36+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll;
6+
const ll INF = 1e18;
7+
const ll mod1 = 1e9 + 7;
8+
const ll mod2 = 998244353;
9+
// Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int findMinDifference(vector<string> &timePoints)
15+
{
16+
int ans = INT_MAX;
17+
int n = timePoints.size();
18+
vector<int> v(n);
19+
for (int i = 0; i < n; i++)
20+
{
21+
string s = timePoints[i];
22+
v[i] = ((s[0] - '0') * 10 + (s[1] - '0')) * 60 + ((s[3] - '0') * 10 + s[4] - '0');
23+
}
24+
sort(v.begin(), v.end());
25+
for (int i = 0; i < n; i++)
26+
{
27+
for (int j = i + 1; j < n; j++)
28+
{
29+
ans = min(ans, v[j] - v[i]);
30+
ans = min(ans, 1440 - (v[j] - v[i]));
31+
}
32+
}
33+
return ans;
34+
}
35+
};

0 commit comments

Comments
(0)

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