题目一:
思路:双指针
bool isSubsequence(char * s, char * t)
{
int fast=0;
int slow=0;
while(slow<strlen(s)&&fast<strlen(t))
{
if(s[slow]==t[fast])
{
slow++;
}
fast++;
}
return slow==strlen(s);
}
题目二
思路:"z"字搜索
bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target)
{
if(target<matrix[0][0]||target>matrix[matrixSize-1][matrixColSize[0]-1])
return false;
int i=matrixSize-1;
int j=0;
while(i>=0&&j<=matrixColSize[0]-1)
{
if(matrix[i][j]==target)
return true;
else if(target<matrix[i][j])
i--;
else
j++;
}
return false;
int numJewelsInStones(char * jewels, char * stones){
int count = 0;
for (int i = 0; i < strlen(jewels); i ++)
{
for (int j = 0; j < strlen(stones); j ++)
{
if (jewels[i] == stones[j])
{
count ++;
}
}
}
return count;
}