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 <iostream> | |
using namespace std; | |
//leetcode supplied function (I've created an example): | |
bool isBadVersion(int n) { | |
return (n >= 4); | |
} | |
int firstBadVersion(int n) { |
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 <iostream> | |
using namespace std; | |
bool knows(int a, int b); | |
int findCelebrity(int n) { | |
if (n==0) return -1; | |
int celeb = 0; | |
for (int i=1; i<n; ++i) { |
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 <iostream> | |
using namespace std; | |
bool knows(int a, int b); | |
int findCelebrity(int n) { | |
for (int b=0; b<n; ++b) { | |
int count=0; | |
for (int a=0; a<n; ++n) { |
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 <iostream> | |
#include <vector> | |
using namespace std; | |
int numWays(int n, int k) { | |
if (n==0 || k==0) return 0; | |
if (n==1) return k; | |
if (n==2) return k*k; | |
vector<int> dp {0,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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int numWays(int n, int k) { | |
if (n==0 || k==0) return 0; | |
vector<int> dp(n,1); | |
for (int c=1; c<n; ++c) { |
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 <iostream> | |
#include <vector> | |
using namespace std; | |
int numWays(int n, int k) { | |
if (n==0 || k==0) return 0; | |
vector<vector<int>> dp(k, vector<int>(n,1)); | |
for (int c=1; c<n; ++c) { |
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 <iostream> | |
#include <vector> | |
using namespace std; | |
int hIndex(vector<int>& citations) { | |
int h=0, len=citations.size(); | |
int l=0, r=len-1, m=l+(r-l)/2; | |
while (l <= r) { | |
m = l+(r-l)/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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int hIndex(vector<int>& citations) { | |
int h=0, len=citations.size(); | |
for (int i=len-1; i>=0; --i) { | |
if (citations[i] >= len-i) h++; | |
else break; |
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 <iostream> | |
#include <vector> | |
using namespace std; | |
int hIndex(vector<int>& citations) { | |
sort(citations.begin(), citations.end(), greater<int>()); | |
int h = 0; | |
for (int i=0; i<citations.size(); ++i) { | |
if (citations[i] > i) h=i+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
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
string concat(string str, const string& strAdd) { | |
if (!strAdd.empty() && strAdd != "Zero") { | |
str += " "; | |
str += strAdd; |
NewerOlder