原题题目
代码实现(首刷自解)
/*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/#define MAX 2500bool visit(struct ListNode* head,struct TreeNode* root)
{
if(!head)return true;if(root){
if(root->val == head->val)return visit(head->next,root->left) || visit(head->next,root->right);elsereturn false;}elsereturn false;
}bool isSubPath(struct ListNode* head, struct TreeNode* root){
if(!root && !head || !head)return true;if(!root)return false;struct TreeNode* queue[MAX],*pos;int top = -1,rear = -1,size = 0;queue[++rear] = root;while(rear != top){
size = rear - top;while(size--){
pos = queue[++top];if(pos->val == head->val){
if(visit(head,pos))return true;}if(pos->left) queue[++rear] = pos->left;if(pos->right) queue[++rear] = pos->right;}}return false;
}
百题记录截图(懒狗记录)
这段时间在准备复习 而且最近耍的有点多 做题每天三道差不多了