Skip to content

Commit d272fdb

Browse files
committed
update
1 parent 778a093 commit d272fdb

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

containsDuplicate.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
bool containsDuplicate(vector<int>& nums) {
4+
map<int,int> res;
5+
for(int i =0 ; i <nums.size(); i++) {
6+
if(res.count(nums[i])){
7+
return true;
8+
}
9+
res.insert(pair<int, int>(nums[i], i));
10+
}
11+
return false;
12+
}
13+
};

deleteNode.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
void deleteNode(ListNode* node) {
12+
if(node ==NULL)
13+
return;
14+
ListNode* nodeNext = node->next;
15+
if(nodeNext){
16+
int value = nodeNext->val;
17+
node->value = value;
18+
noe->enxt = nodeNext->next;
19+
}
20+
}
21+
}

findRelativeRanks.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
vector<string> findRelativeRanks(vector<int>& nums) {
4+
vector<pair<int,int>> vec;
5+
vector<string> res(nums.size());
6+
string ranks[3] = {"Gold Medal", "Silver Medal", "Bronze Medal"};
7+
for( int i =0 ; i < nums.size(); i++)
8+
vec.push_back(pair<int,int>(i, nums[i]));
9+
auto cmp = [](const pair<int, int>& p1, const pair<int, int>& p2)
10+
{
11+
return p1.second >p2.second;
12+
};
13+
sort(vec.begin(), vec.end(), cmp);
14+
15+
for(int i = 0; i < nums.size(); ++i)
16+
{
17+
if(i < 3) res[vec[i].first] = ranks[i];
18+
else res[vec[i].first] = to_string(i+1);
19+
}
20+
return res;
21+
22+
}
23+
};

isAnagram.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool isAnagram(string s, string t) {
4+
vector<int> count(26,0);
5+
for(int i = 0; i < s.length(); i++) {
6+
count[s[i]-'a']++;
7+
}
8+
9+
for(int i = 0; i < t.length(); i++) {
10+
count[t[i]-'a']--;
11+
}
12+
13+
for(int i = 0; i < count.size(); i++)
14+
{
15+
if(count[i] != 0)
16+
return false;
17+
}
18+
19+
return true;
20+
}
21+
};

0 commit comments

Comments
 (0)