Skip to content

Commit b3206a5

Browse files
author
josipmaric
committed
Added 21.02. and 22.02.
1 parent dd83659 commit b3206a5

File tree

7 files changed

+97
-2
lines changed

7 files changed

+97
-2
lines changed

21_02_2022_MajoritiElement/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// main.cpp
3+
// AlgorithmADay
4+
//
5+
// Created by josipmaric on 21.02.2022..
6+
//
7+
8+
int majorityElement(vector<int>& nums) {
9+
unordered_map<int, int> occurences;
10+
11+
if(nums.size() == 1) {
12+
return nums[0];
13+
}
14+
15+
for(int i = 0; i < nums.size(); i++) {
16+
auto it = occurences.find(nums[i]);
17+
if (it == occurences.end() ) {
18+
occurences.insert ( std::pair<int,int>(nums[i], 1) );
19+
} else {
20+
it->second += 1;
21+
if(it->second > nums.size()/2) {
22+
return nums[i];
23+
}
24+
}
25+
}
26+
27+
return 0;
28+
}

21_02_2022_MajoritiElement/text.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Given an array nums of size n, return the majority element.
2+
3+
The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
4+
5+
6+
7+
Example 1:
8+
9+
Input: nums = [3,2,3]
10+
Output: 3
11+
Example 2:
12+
13+
Input: nums = [2,2,1,1,1,2,2]
14+
Output: 2
15+
16+
17+
Constraints:
18+
19+
n == nums.length
20+
1 <= n <= 5 * 104
21+
-231 <= nums[i] <= 231 - 1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// main.cpp
3+
// AlgorithmADay
4+
//
5+
// Created by josipmaric on 22.02.2022..
6+
//
7+
8+
int titleToNumber(string columnTitle) {
9+
int number = 0;
10+
for (int i = 0; i < columnTitle.size(); i++) {
11+
int currentLetter = (int) columnTitle[i] - 64;
12+
number = number * 26 + currentLetter;
13+
}
14+
return number;
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number.
2+
3+
For example:
4+
5+
A -> 1
6+
B -> 2
7+
C -> 3
8+
...
9+
Z -> 26
10+
AA -> 27
11+
AB -> 28
12+
...
13+
14+
15+
Example 1:
16+
17+
Input: columnTitle = "A"
18+
Output: 1
19+
Example 2:
20+
21+
Input: columnTitle = "AB"
22+
Output: 28
23+
Example 3:
24+
25+
Input: columnTitle = "ZY"
26+
Output: 701
27+
28+
29+
Constraints:
30+
31+
1 <= columnTitle.length <= 7
32+
columnTitle consists only of uppercase English letters.
33+
columnTitle is in the range ["A", "FXSHRXW"].

RemoveCoveredIntervals/results.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)