This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Member(val no:Long, val name: String) | |
fun main() { | |
val list = listOf(Member(1, "일"), Member(1, "이"), Member(3, "삼")) | |
val result = list.groupBy({it.no}, {it.name}) | |
println(result) // {1=[일, 이], 3=[삼]} | |
println(result[1]) // [일, 이] | |
println(result[2]) // null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
/* | |
* 시간복잡도 : O(N) | |
*/ | |
// sliding window | |
int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int X) { | |
int l = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <map> | |
#include <algorithm> | |
using namespace std; | |
bool compare(pair<int,int>& a, pair<int,int>& b){ | |
// 3. 장르 내에서 재생 횟수가 같은 노래 중에서는 고유 번호가 낮은 노래를 먼저 수록합니다. | |
if(a.first == b.first){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
private: | |
int dx[4] = {-1, 1, 0, 0}; | |
int dy[4] = {0, 0, -1, 1}; | |
public: | |
int getAnswer(int x, int y, vector<vector<int>>& A){ | |
int r = A.size(); | |
int c = A[0].size(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int maxScoreSightseeingPair(vector<int>& A) { | |
int l = 0, r = 0; | |
int answer = -1e5; | |
for(int r=1; r<A.size(); r++){ | |
answer =max(answer, A[l] + A[r] + l - r); | |
if(A[l] <= A[r] + r - l) | |
l = r; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int shipWithinDays(vector<int>& weights, int D) { | |
// find minimum weights can Answer | |
int l = 0; | |
int r = 0; | |
for(int i=0;i<weights.size();i++){ | |
int nowWeight = weights[i]; | |
l = max(l, nowWeight); | |
r += nowWeight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int numPairsDivisibleBy60(vector<int>& time) { | |
map<int, int> m; | |
int answer = 0; | |
for(int i=0;i<time.size();i++){ | |
int rest = time[i] % 60; | |
m[rest]++; | |
} | |
for(map<int,int>::iterator it = m.begin(); it != m.end(); it++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int bitwiseComplement(int N) { | |
if(N == 0) return 1; | |
int tmp = 1; | |
int answer = 0; | |
while(0 < N){ | |
answer += ((N + 1) % 2) * tmp; | |
N /= 2; | |
tmp *= 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int largestSumAfterKNegations(vector<int>& A, int K) { | |
sort(A.begin(), A.end()); | |
int answer = 0; | |
int lastMinus = 1e9; | |
for(int i=0;i<A.size();i++){ | |
if(A[i] < 0){ | |
if(0 < K){ | |
A[i] *= -1; K--; |
NewerOlder