Skip to content

Instantly share code, notes, and snippets.

View egraldlo's full-sized avatar

Lei Zhang egraldlo

  • NEU -- ECNU
  • Shanghai. Putuo
View GitHub Profile
@egraldlo
egraldlo / leetcode-reverse_words
Last active August 29, 2015 14:04
reverse words in a string in leetcode
#include <stack>
#include <string>
using namespace std;
class Solution {
public:
void reverseWords(string &s) {
stack<string> stk;
int i=0;
int left=0;
@egraldlo
egraldlo / leetcode-valid_palindrome
Last active August 29, 2015 14:04
leetcode, valid palindrome, it's easy, -_-
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);
__kernel
void bitonicSort(__global uint * theArray,
const uint stage,
const uint passOfStage,
const uint direction)
{
uint sortIncreasing = direction;
uint threadId = get_global_id(0);
@egraldlo
egraldlo / generate-random
Created August 7, 2014 08:21
generate random number
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;
@egraldlo
egraldlo / leetcode-Insertion_sort_list
Last active August 29, 2015 14:05
using list to do insertion sort
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@egraldlo
egraldlo / leetcode-search_range
Created August 11, 2014 10:07
search for a range
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;
}
@egraldlo
egraldlo / leetcode-reorder_list
Created August 12, 2014 01:59
reorder list
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@egraldlo
egraldlo / leetcode-reverse_integer
Created August 15, 2014 03:52
reverse integer
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;
@egraldlo
egraldlo / llw
Last active August 29, 2015 14:06
length of last word
class Solution {
public:
int lengthOfLastWord(const char *s) {
int len=0;
/* 字符串的遍历方式,始终这样写,下面肯定要有个s++ */
while(*s!='\0'){
/* 当本字符不是空格的时候,+1 */
if(*s!=' ')
len++;
/* 如果本字符等于空格,而下一个字符不等于空格的时候,重新开始计数 */