Skip to content

Commit e48a35e

Browse files
committed
leetcode_biweek_26
1 parent 3df67f9 commit e48a35e

4 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
int goodNodes(TreeNode* root) {
15+
16+
}
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public:
3+
string largestNumber(vector<int>& cost, int target) {
4+
5+
}
6+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* AC
3+
*
4+
*/
5+
class Solution {
6+
public:
7+
int maxPower(string s) {
8+
int ret = 1;
9+
int nowLength = 1;
10+
int size = s.length();
11+
char nowChar = s[0];
12+
13+
for (int i = 1; i < size; i++) {
14+
if (s[i] == nowChar) {
15+
nowLength++;
16+
if (nowLength > ret) {
17+
ret = nowLength;
18+
}
19+
}
20+
else {
21+
nowLength = 1;
22+
nowChar = s[i];
23+
}
24+
}
25+
26+
return ret;
27+
28+
}
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* AC
3+
*
4+
*/
5+
class Solution {
6+
public:
7+
vector<string> simplifiedFractions(int n) {
8+
vector<string> ret;
9+
if (n == 1) {
10+
return ret;
11+
}
12+
13+
// 用 set 对结果去重
14+
set<string> record;
15+
16+
for (int i = 2; i <= n; i++) {
17+
// 求出分母为 i 下的所有最简真分数,添加进 set
18+
int num1, num2, temp;
19+
for (int j = 1; j < i; j++) {
20+
num1 = i;
21+
num2 = j;
22+
23+
while (num2 != 0) {
24+
temp = num1 % num2;
25+
num1 = num2;
26+
num2 = temp;
27+
}
28+
if (num1 == 1) {
29+
string result = to_string(j) + "/" + to_string(i);
30+
record.insert(result);
31+
}
32+
}
33+
}
34+
35+
set<string>::iterator it;
36+
for(it = record.begin(); it != record.end(); it++) {
37+
ret.push_back(*it);
38+
}
39+
40+
return ret;
41+
}
42+
};

0 commit comments

Comments
 (0)