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
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
import java.util.Scanner; | |
class Main { |
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--; |
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
/** | |
* 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
// | |
// Created by fpdjsns | |
// Copyright © 2019 fpdjsns. All rights reserved. | |
// | |
#include<iostream> | |
#include<vector> | |
#include<algorithm> | |
#include<string> | |
#include<queue> |