Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View fpdjsns's full-sized avatar
😄
인생의 풍류를 즐기는 중

withham fpdjsns

😄
인생의 풍류를 즐기는 중
View GitHub Profile
@fpdjsns
fpdjsns / kotlin_list_groupBy.kt
Last active October 15, 2019 23:38
Kotlin list.groupBy
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
}
class Solution {
public:
/*
* 시간복잡도 : O(N)
*/
// sliding window
int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int X) {
int l = 0;
#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){
/**
* 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 {
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();
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;
}
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;
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++){
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;
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--;