Skip to main content
572, Subtree of Another Tree

I Problem

Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.


MikeAbout 3 minbinary treeeasybinary treedepth first searchstring matchinghash function
459, Repeated Substring Pattern

I Problem

Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

Example 1
Input: s = "abab"
Output: true
Explanation: It is the substring "ab" twice.


MikeAbout 1 minstringeasystringstring matching
28, Find the Index of the First Occurrence in a String

I Problem

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Example 1
Input: haystack = "sadbutsad", needle = "sad"
Output: 0
Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0.


MikeAbout 2 minstringeasystringstring matchingtwo pointers