mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										36
									
								
								24/11/3258.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								24/11/3258.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
int countKConstraintSubstrings(string s, int k)
 | 
			
		||||
{
 | 
			
		||||
    int a, b;
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    for (int i = 1; i <= s.length(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        int j = 0;
 | 
			
		||||
        while (j + i <= s.length())
 | 
			
		||||
        {
 | 
			
		||||
            a = 0;
 | 
			
		||||
            b = 0;
 | 
			
		||||
            for (int k = j; k < j + i; k++)
 | 
			
		||||
            {
 | 
			
		||||
                if (s[k] == '0')
 | 
			
		||||
                {
 | 
			
		||||
                    a++;
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    b++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (a <= k || b <= k)
 | 
			
		||||
            {
 | 
			
		||||
                count++;
 | 
			
		||||
                cout << j << " " << j + i << " " << a << " " << b << endl;
 | 
			
		||||
            }
 | 
			
		||||
            j++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user