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 <stack> | |
#include <string> | |
using namespace std; | |
class Solution { | |
public: | |
void reverseWords(string &s) { | |
stack<string> stk; | |
int i=0; | |
int left=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
class Solution { | |
public: | |
bool isPalindrome(string s) { | |
stack<char> sc,sc2; | |
stack<char> sc1; | |
unsigned i=0; | |
while(i<s.length()){ | |
char c=s.at(i); | |
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9')){ | |
sc.push(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
__kernel | |
void bitonicSort(__global uint * theArray, | |
const uint stage, | |
const uint passOfStage, | |
const uint direction) | |
{ | |
uint sortIncreasing = direction; | |
uint threadId = get_global_id(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
int main(){ | |
FILE *fd; | |
if((fd=fopen("sorttest","wb"))!=0){ | |
cout<<"error in opening file!"<<endl; | |
} | |
else{ | |
cout<<"open file failed!"<<endl; | |
} | |
int f0,f1,f2,f3,f4; |
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 singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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> searchRange(int A[], int n, int target) { | |
vector<int> ret; | |
int point=binarySearch(A,0,n-1,target); | |
if(point==-1){ | |
ret.push_back(-1); | |
ret.push_back(-1); | |
return ret; | |
} |
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 singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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 i=0,j=0; | |
while(x){ | |
i=x%10; | |
j=i+j*10; | |
x=x/10; | |
} | |
return 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
int binary_search(int A[], int beg, int end, int target) | |
{ | |
int i = beg, j = end; | |
while (i < j) | |
{ | |
int mid = (i + j) / 2; | |
if (target < A[mid]) | |
j = mid; | |
else if (target > A[mid]) | |
i = mid + 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 lengthOfLastWord(const char *s) { | |
int len=0; | |
/* 字符串的遍历方式,始终这样写,下面肯定要有个s++ */ | |
while(*s!='\0'){ | |
/* 当本字符不是空格的时候,+1 */ | |
if(*s!=' ') | |
len++; | |
/* 如果本字符等于空格,而下一个字符不等于空格的时候,重新开始计数 */ |
OlderNewer