Compare commits
7 Commits
f198c184ad
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c36e503041 | |||
| 67baf83d27 | |||
| f5bc575378 | |||
|
|
f151c946a2 | ||
|
|
1951556e4b | ||
|
|
3017764da1 | ||
|
|
b705590f4b |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,2 +1,5 @@
|
||||
.vscode
|
||||
build
|
||||
build
|
||||
/.vs
|
||||
/.vscode
|
||||
*.exe
|
||||
|
||||
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@@ -6,7 +6,8 @@
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
||||
20
724.cpp
Normal file
20
724.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
class Solution {
|
||||
public:
|
||||
int pivotIndex(vector<int>& nums) {
|
||||
|
||||
if(nums.size() == 0) return -1;
|
||||
|
||||
vector<int> leftSum(nums.size(),0);
|
||||
|
||||
for(auto i = 0; i < nums.size(); i++){
|
||||
leftSum[i] += nums[i];
|
||||
}
|
||||
|
||||
for(auto i = 0; i < nums.size(); i++){
|
||||
if(2 * leftSum[i] - nums[i] == leftSum[nums.size() - 1]){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
project(lc VERSION 0.1.0)
|
||||
|
||||
include(CTest)
|
||||
|
||||
31
main.cpp
31
main.cpp
@@ -4,18 +4,37 @@
|
||||
using namespace std;
|
||||
|
||||
struct ListNode {
|
||||
int val;
|
||||
ListNode *next;
|
||||
ListNode(int x) : val(x), next(NULL) {}
|
||||
int val;
|
||||
ListNode* next;
|
||||
// ListNode(int x) : val(x), next(NULL) {} //
|
||||
ListNode(int x, ListNode* n = NULL) : val(x), next(n) {}
|
||||
};
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
vector<int> reversePrint(ListNode* head) {
|
||||
|
||||
reverse(head);
|
||||
return (result);
|
||||
}
|
||||
|
||||
private:
|
||||
vector<int> result;
|
||||
void reverse(ListNode* head) {
|
||||
if (head != nullptr) {
|
||||
if (head->next != nullptr) {
|
||||
reversePrint(head->next);
|
||||
}
|
||||
result.push_back(head->val);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
std::cout << "Hello, world!\n";
|
||||
|
||||
ListNode* head = new ListNode(1);
|
||||
head -> next = new ListNode(3);
|
||||
head -> next -> next = new ListNode(2);
|
||||
|
||||
Solution s;
|
||||
std::cout << s.reversePrint(head)[0] << s.reversePrint(head)[1] << s.reversePrint(head)[2] << std::endl;
|
||||
}
|
||||
|
||||
47
offer06.cpp
47
offer06.cpp
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* @Description:
|
||||
* @Version: 1.0
|
||||
* @Autor: wxchen
|
||||
* @Date: 2022-11-21 15:27:10
|
||||
* @LastEditTime: 2022-11-21 21:06:07
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct ListNode {
|
||||
int val;
|
||||
ListNode* next;
|
||||
// ListNode(int x) : val(x), next(NULL) {} //
|
||||
ListNode(int x, ListNode* n = NULL) : val(x), next(n) {}
|
||||
};
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> reversePrint(ListNode* head) {
|
||||
reverse(head);
|
||||
return (result);
|
||||
}
|
||||
|
||||
private:
|
||||
vector<int> result;
|
||||
void reverse(ListNode* head) {
|
||||
if (head != nullptr) {
|
||||
if (head->next != nullptr) {
|
||||
reversePrint(head->next);
|
||||
}
|
||||
result.push_back(head->val);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
// ListNode* head = new ListNode(1);
|
||||
// head -> next = new ListNode(3);
|
||||
// head -> next -> next = new ListNode(2);
|
||||
|
||||
Solution s;
|
||||
std::cout << s.reversePrint(head)[0] << s.reversePrint(head)[1] << s.reversePrint(head)[2] << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user