C#C
C#3y ago
morry329#

✅ 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;
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?
Bildschirmfoto_2023-07-29_um_17.27.30.png
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.
Was this page helpful?