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<cstdio> | |
#include<stack> | |
using namespace std; | |
struct ListNode{ | |
int val; | |
ListNode *next; | |
}; | |
void addToTail(ListNode **head,ListNode **cur,int value){ | |
ListNode *temp=new ListNode(); |
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<stdio.h> | |
int main(){ | |
char ret[1000000]; | |
gets(ret); | |
int originalLen=0; | |
int numberOfBlank=0; | |
int i=0; | |
while(ret[i]!='\0'){ | |
originalLen++; |
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
C++: | |
class Solution { | |
public: | |
double findMedianSortedArrays(int A[], int m, int B[], int n) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int k=m+n; | |
if(k&0x1) return findKth(A,m,B,n,k/2+1); | |
else return (findKth(A,m,B,n,k/2)+findKth(A,m,B,n,k/2+1))/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
C++: | |
class Solution { | |
private: | |
bool canUse[256]; | |
public: | |
int lengthOfLongestSubstring(string s) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
memset(canUse,true,sizeof(canUse)); | |
int start=0; |
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
C++: | |
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(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
C++: | |
class Solution { | |
public: | |
string longestPalindrome(string s) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(s.size()==0) return ""; | |
string ret; | |
string cur; | |
for(int i=0;i<s.size();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
C++: | |
class Solution { | |
public: | |
string convert(string s, int nRows) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(nRows==1) return s; | |
string temp[nRows]; | |
int idx=-1; | |
int step=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
C++: | |
class Solution { | |
public: | |
int reverse(int x) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int res=0; | |
while(x!=0){ | |
res=res*10+x%10; | |
x=x/10; |
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
C++: | |
class Solution { | |
public: | |
int atoi(const char *str) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
bool negative=false; | |
while(*str==' ') str++; | |
if(*str=='-'){ | |
negative=true; |
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
C++: | |
class Solution { | |
public: | |
bool isPalindrome(int x) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(x<0) return false; | |
int base=1; | |
while(x/base>=10) base *=10; | |
while(x){ |
NewerOlder