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 0baf54e

Browse files
Changes for Day 29
1 parent 741f46e commit 0baf54e

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class FirstUnique {
2+
vector<int> nums;
3+
unordered_map<int, int> countMap;
4+
int firstUniquePos;
5+
public:
6+
FirstUnique(vector<int>& nums) {
7+
for(int i=0; i<nums.size(); i++){
8+
add(nums[i]);
9+
}
10+
firstUniquePos = 0;
11+
showFirstUnique();
12+
}
13+
14+
int showFirstUnique() {
15+
for(int i=firstUniquePos; i < nums.size(); i++){
16+
if(countMap[nums[i]] == 1){
17+
firstUniquePos = i;
18+
return nums[i];
19+
}
20+
}
21+
return -1;
22+
}
23+
24+
void add(int value) {
25+
if(countMap.find(value) == countMap.end())
26+
{
27+
nums.push_back(value);
28+
countMap[value] = 1;
29+
} else {
30+
countMap[value]++;
31+
}
32+
}
33+
};
34+
35+
/**
36+
* Your FirstUnique object will be instantiated and called as such:
37+
* FirstUnique* obj = new FirstUnique(nums);
38+
* int param_1 = obj->showFirstUnique();
39+
* obj->add(value);
40+
*/

‎30 Days Challenge/Maximal Square.cpp‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
struct Node
2+
{
3+
Node(){
4+
leftOnes = 0;
5+
upOnes = 0;
6+
maxSquare = 0;
7+
}
8+
int leftOnes;
9+
int upOnes;
10+
int maxSquare;
11+
};
12+
13+
class Solution {
14+
public:
15+
int maximalSquare(vector<vector<char>>& matrix) {
16+
if(matrix.size() == 0){
17+
return 0;
18+
}
19+
vector<vector<Node>> map =
20+
vector<vector<Node>>(matrix.size(), vector<Node>(matrix[0].size(), Node()));
21+
int maxSq = 0;
22+
for(int j=0; j<matrix[0].size(); j++){
23+
for(int i=0; i<matrix.size(); i++){
24+
if(matrix[i][j] == '1'){
25+
map[i][j].upOnes = i > 0 ? map[i-1][j].upOnes + 1 : 1;
26+
}
27+
}
28+
}
29+
for(int i=0; i<matrix.size(); i++){
30+
for(int j=0; j<matrix[0].size(); j++){
31+
if(matrix[i][j] == '1'){
32+
map[i][j].leftOnes = j > 0 ? map[i][j-1].leftOnes + 1 : 1;
33+
map[i][j].maxSquare = i > 0 && j > 0 ?
34+
min(map[i-1][j-1].maxSquare + 1, min(map[i][j].leftOnes, map[i][j].upOnes))
35+
: 1;
36+
maxSq = max(maxSq, map[i][j].maxSquare);
37+
}
38+
}
39+
}
40+
return maxSq * maxSq;
41+
}
42+
};

0 commit comments

Comments
(0)

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