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 <zlib.h> | |
#include <time.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <sys/uio.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <inttypes.h> | |
#include "kseq.h" | |
#include "kstring.h" |
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
library(ggplot2) | |
library(scales) | |
library(ggpubr) | |
k = read.csv('iostat.tsv') | |
k$datetime <- as.POSIXct(k$time, origin="1970-01-01", tz="GMT") | |
s1 <- ggplot(k, aes(datetime)) + | |
geom_line(aes(y = rs, colour="rs"), alpha=0.4, size=1) + | |
geom_line(aes(y = ws, colour="ws"), alpha=0.4, size=1) + |
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 trailingZeroes(int n) { | |
if (n < 5) return 0; | |
int count = 0; | |
while(n >= 5) { | |
count += floor(n/5); | |
n /= 5; | |
} | |
return count; |
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
vector<vector<int> > C(s1.length() + 1, vector<int>(s2.length() + 1, 0)); | |
// initial | |
for (int i = 1; i < s2.length() + 1; ++i) { | |
C[0][i] = C[0][i - 1] + s2[i - 1]; | |
} | |
for (int i = 1; i < s1.length() + 1; ++i) { | |
C[i][0] = C[i - 1][0] + s1[i - 1]; | |
} | |
for (int i = 1; i < s1.length() + 1; ++i) { | |
for (int j = 1; j < s2.length() + 1; ++j) { |
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 numberOfArithmeticSlices(vector<int>& A) { | |
int count = 0; | |
int added = 0; | |
int n = A.size(); | |
for(int i = 2; i < n; i++) { | |
if (A[i-1] - A[i] == A[i-2] - A[i-1]) { | |
count += ++added; | |
} else { |
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 reverse(int x) { | |
int rev = 0; | |
while (x != 0) { | |
int pop = x % 10; | |
x /= 10; | |
if (rev > INT_MAX/10 || rev == INT_MAX/10 && pop > 7) return 0; | |
if (rev < INT_MIN/10 || rev == INT_MIN/10 && pop < -8) return 0; | |
rev = rev * 10 + pop; |
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 countSubstrings(string s) { | |
int ans = 0; | |
for (int i = 0; i < s.length();i++) { | |
ans += count(s, i, i); | |
ans += count(s, i, i+1); | |
} | |
return ans; | |
} |
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: | |
vector<int> countBits(int num) { | |
vector<int> res = vector<int>(num+1, 0); | |
for(int i = 1; i <= num; i++) { | |
res[i] = res[i >> 1] + (i & 1); | |
} | |
return res; | |
} | |
}; |
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 shoppingOffers(vector<int>& price, vector<vector<int>>& special, vector<int>& needs) { | |
int res = inner_product(price.begin(), price.end(), needs.begin(), 0); | |
for (auto offer: special) { | |
vector<int> r = helper(offer, needs); | |
if (r.empty()) continue; | |
res = min(res, shoppingOffers(price, special, r) + offer.back()); | |
} | |
return res; |
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: | |
bool makesquare(vector<int>& nums) { | |
if (nums.empty() || nums.size() < 4) return false; | |
int sum = accumulate(nums.begin(), nums.end(), 0); | |
if (sum % 4 != 0) return false; | |
int n = nums.size(), all = (1 << n) - 1, target = sum/4; | |
vector<int> masks, validHalf(1<<n, false); | |
for(int i = 0; i < all; i++) { | |
int curSum = 0; |
NewerOlder