Skip to content

Commit 056f8f6

Browse files
committed
2347 solved.
1 parent f78380b commit 056f8f6

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(cpp_2347)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_2347 main.cpp)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/// Source : https://leetcode.com/problems/best-poker-hand/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-07-23
4+
5+
#include <iostream>
6+
#include <vector>
7+
8+
using namespace std;
9+
10+
11+
/// Simulation
12+
/// Time Complexity: O(nlogn)
13+
/// Space Complexity: O(1)
14+
class Solution {
15+
public:
16+
string bestHand(vector<int>& ranks, vector<char>& suits) {
17+
18+
if(is_flush(suits)) return "Flush";
19+
20+
sort(ranks.begin(), ranks.end());
21+
int max_same = get_max_same(ranks);
22+
if(max_same >= 3) return "Three of a Kind";
23+
else if(max_same == 2) return "Pair";
24+
return "High Card";
25+
}
26+
27+
private:
28+
int get_max_same(const vector<int>& data){
29+
30+
int n = data.size(), res = 0;
31+
for(int start = 0, i = 1; i <= n; i ++)
32+
if(i == n || data[i] != data[start]){
33+
res = max(res, i - start);
34+
start = i;
35+
}
36+
return res;
37+
}
38+
39+
bool is_flush(const vector<char>& suits){
40+
for(int i = 1; i < suits.size(); i ++)
41+
if(suits[i] != suits[0]) return false;
42+
return true;
43+
}
44+
};
45+
46+
47+
int main() {
48+
49+
return 0;
50+
}

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,8 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
21962196
| 2343 | [Query Kth Smallest Trimmed Number](https://leetcode.com/problems/query-kth-smallest-trimmed-number/) | [] | [C++](2001-2500/2343-Query-Kth-Smallest-Trimmed-Number/cpp-2343/) | | |
21972197
| 2344 | [Minimum Deletions to Make Array Divisible](https://leetcode.com/problems/minimum-deletions-to-make-array-divisible/) | [] | [C++](2001-2500/2344-Minimum-Deletions-to-Make-Array-Divisible/cpp-2344/) | | |
21982198
| 2345 | [Finding the Number of Visible Mountains](https://leetcode.com/problems/finding-the-number-of-visible-mountains/) | [] | [C++](2001-2500/2345-Finding-the-Number-of-Visible-Mountains/cpp-2345/) | | |
2199+
| 2346 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
2200+
| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand/) | [] | [C++](2001-2500/2347-Best-Poker-Hand/cpp-2347/) | | |
21992201
| | | | | | |
22002202

22012203
## 力扣中文站比赛

0 commit comments

Comments
 (0)