Skip to content

Commit

Permalink
⚡ perf: change array to vector
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchuo committed Mar 19, 2019
1 parent 09af9b1 commit 0965714
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions AdvancedLevel_C++/1101. Quick Sort (25).cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include <iostream>
#include <algorithm>
#include <vector>
int a[100000], b[100000];
int v[100000];
using namespace std;
int main() {
int n;
int n, max = 0, cnt = 0;
scanf("%d", &n);
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(a, a + n);
int v[100000], max = 0, cnt = 0;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if(a[i] == b[i] && b[i] > max)
v[cnt++] = b[i];
Expand Down
7 changes: 4 additions & 3 deletions BasicLevel_C++/1045. 快速排序(25).cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include <iostream>
#include <algorithm>
#include <vector>
int a[100000], b[100000], v[100000];
int v[100000];
using namespace std;
int main() {
int n, max = 0, cnt = 0;
scanf("%d", &n);
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(a, a + n);
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if(a[i] == b[i] && b[i] > max)
v[cnt++] = b[i];
Expand All @@ -22,6 +23,6 @@ int main() {
if (i != 0) printf(" ");
printf("%d", v[i]);
}
printf("\n");//不加这句会有一个测试点没法通过。.
printf("\n");
return 0;
}

0 comments on commit 0965714

Please sign in to comment.