Archive
2020.03.13
class Solution { public: vector twoSum(vector& nums, int target) { vector answer (2); unsigned int length = nums.size(); for(int i = 0 ; i < length; i++) { unsigned int left = nums.at(i); for(int j = i+1 ; j < length; j++) { if((left + nums[j]) == target) { //answer.push_back(i); //answer.push_back(j); answer[0] = i; answer[1] = j; } } } return answer; } }; push_back 하면 런타임이 조금 더 걸림. (0.1초 정도?) ..
Archive
2020.03.13
class Solution { public: void reverseString(vector& s) { if(!s.at(0)) return; int aPointer = 0; int bPointer = s.size()-1; while(aPointer
Archive
2020.03.12
#include #include #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; int i, j, k; for(int m = 0 ; m < commands.size(); m++) { i = commands[m][0]; j = commands[m][1]; k = commands[m][2]; vector temp (j - i + 1); for(int n = i ; i
Archive
2020.03.12
#include #include #include using namespace std; string solution(vector participant, vector completion) { string answer = ""; sort(participant.begin(), participant.end()); sort(completion.begin(),completion.end()); for(int i = 0 ; i < participant.size(); i++) { if(participant[i] != completion[i]) { return participant[i]; } } return answer; }