✅ Why does my list get zeroed?
I am getting swamped with this puzzle https://leetcode.com/problems/find-all-anagrams-in-a-string/
My WIP is as follows;
This code gives me the result as per attached photo. How come my list does not store anything?
My WIP is as follows;
public class Solution {
public IList<int> FindAnagrams(string s, string p) {
List<int> items = new List<int>();
int i = 0;
while(i < s.Length){ //loop through the s which is longer than p
if(p.Length == s.Substring(i).Length && p.Contains(s.Substring(i))){ //edge case where s and p are of the same length
items.Add(p.Length);
} else if(p.Contains(s.Substring(i))){
items.Add(p.Length);
}
i++;
}
return items;
}
}This code gives me the result as per attached photo. How come my list does not store anything?

LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
