This file contains hidden or 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 <iostream> | |
| #include <vector> | |
| using namespace std; | |
| double coinProbK(vector<double>& c, int k) { | |
| int n = c.size(); | |
| vector<vector<double> > dp(n + 1, vector<double>(k + 1, 0.0)); | |
| dp[0][0] = 1.0; | |
| for (int i = 1; i <= n; i++) { | |
| dp[i][0] = dp[i-1][0] * (1 - c[i-1]); |
This file contains hidden or 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
| // https://www.youtube.com/watch?v=GTJr8OvyEVQ | |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| vector<int> KMPpreprocessing(string needle) { | |
| int len = needle.size(); | |
| vector<int> match(len, 0); | |
| int j = 0; | |
| for (int i = 1; i < len; i++) { |
This file contains hidden or 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 <iostream> | |
| #include <math.h> | |
| using namespace std; | |
| class Solution { | |
| public: | |
| int one(int num) { | |
| if (num / 10 == 0) { | |
| return num == 0 ? 0 : 1; | |
| } |
This file contains hidden or 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 <iostream> | |
| #include <string> | |
| using namespace std; | |
| string findMin(string s, int k) { | |
| string res = ""; | |
| int len = s.size(); | |
| for (int i = 0; i < len; i++) { | |
| while (!res.empty() and res.back() > s[i] and len - i + res.size() > k) { | |
| res.pop_back(); |
This file contains hidden or 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 <vector> | |
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| int minInsert(string s) { | |
| int i = 0; | |
| int j = s.size() - 1; | |
| int cnt1 = 0; |
This file contains hidden or 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 os | |
| import struct | |
| import numpy as np | |
| """ | |
| Loosely inspired by http://abel.ee.ucla.edu/cvxopt/_downloads/mnist.py | |
| which is GPL licensed. | |
| """ | |
| def read(dataset = "training", path = "."): |