id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "#include<unordered_map>\n\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unordered_map<char, int> alphabet;\n alphabet.reserve(256);\n\n int length = 0;\n string::iterator i, j;\n for (i = s.begin(); i != s.end();) {\n alphabet.empla... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n=s.size();\n int l=300;\n // vector<int> v(l,0);\n // int l=300;\n // int v[l]={0};\n // v[]={0};\n int d=0;\n for(int i=0;i<n;i++){\n int m=0;\n vector<i... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(std::string s) {\n int n = s.length();\n int k = 0;\n int current_size = 0;\n int after_size = 0;\n std::unordered_set<char> mySet;\n\n if (n == 1)\n return 1;\n\n for (size_t i = 0; i <... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(std::string s) {\n int n = s.length();\n int k = 0;\n int current_size = 0;\n int after_size = 0;\n std::unordered_set<char> mySet;\n\n if (n == 1)\n return 1;\n\n for (size_t i = 0; i <... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size();\n if (n < 1) return n;\n int res = 1;\n vector<int> dp(n, 1); //dp[i] represents longest substring starting at index i (fixed left endpoint)\n unordered_map<char, int> freqs;\n\n\nfor ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size();\n if (n < 1) return n;\n int res = 1;\n vector<int> dp(n, 1); //dp[i] represents longest substring starting at index i (fixed left endpoint)\n unordered_map<char, int> freqs;\n\n\nfor ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.size() == 0) return 0;\n unordered_set<char> SeenChars;\n int LongestSubstringLength = 1;\n int Index1 = 0;\n int Index2 = 1;\n while(Index2 < s.size()){\n SeenChars.clear();\... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size();\n vector < vector<bool>>a(n, vector<bool>(n,0));\n for (int i = 0; i < n; i++)a[i][i] = 1;\n \n for (int di = 1; di <= n - 1; di++) {\n bool all_is_0=0;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "\nclass Solution\n{\npublic:\n int lengthOfLongestSubstring(string s)\n {\n string bestSubstring = \"\";\n int startIndex = 0;\n unordered_map<char, int> existingCharacters = {};\n\n while (startIndex < s.size())\n {\n int nextIndex = startIndex + 1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int maxx=0;\n unordered_map<char,int>mp;\n for(int i=0;i<s.size();i++){\n string temp = \"\";\n for(int j=i;j<s.size();j++){\n mp[s[j]]++;\n if(mp[s[j]]>1) brea... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int ans = 0;\n unordered_set<char> set;\n\n for(int i=0;i<s.size();i++){\n string temp = \"\";\n for(int j = i;j<s.size();j++){\n if(set.find(s[j]) == set.end()){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isValid(queue<char> s, char c) {\n while (!s.empty()) {\n if (s.front() == c)\n return false;\n s.pop();\n }\n return true;\n }\n\n int lengthOfLongestSubstring(string s) {\n queue<char> qu;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unordered_map<char, bool> map;\n vector<string> substrings;\n for (int j = 0; j < s.size(); j++){\n string str = \"\";\n map.clear();\n for (int i = j; i < s.size(); i++){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unordered_map<char, bool> map;\n vector<string> substrings;\n for (int j = 0; j < s.size(); j++){\n string str = \"\";\n map.clear();\n for (int i = j; i < s.size(); i++){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n std::unordered_map<char, int> dict;\n int ans = 0;\n for (int i = 0; i < s.length(); ++i)\n {\n std::unordered_map<char,int>::iterator I = dict.find(s[i]);\n if(I == dict.end()) ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n std::unordered_map<char, int> dict;\n int ans = 0;\n for (int i = 0; i < s.length(); ++i)\n {\n if(dict.find(s[i]) == dict.end()) \n dict[s[i]] = i; \n el... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isAllWhitespace(string str) {\n for (char ch : str) {\n if (!isspace(ch)) {\n return false;\n }\n }\n return true;\n }\n bool checkDuplicate(string s) {\n string temp;\n for(int i = 0; i < s.le... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unordered_map<char, long> unique;\n int max_unique = 0;\n int current_count = 0;\n long left = 0;\n long right = s.size() - 1;\n bool left_to_right = true;\n \n while (left <= r... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int max = 0;\n std::unordered_map<char, size_t> cache;\n for(size_t i = 0; i < s.size(); ++i)\n {\n const auto it = cache.find(s[i]);\n if(it != cache.end())\n {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "using namespace std;\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int maxsize=0,cur=0;\n unordered_map<char,pair<int,int>> alphabet;\n for (int i=0;i<s.size();i++){\n if (alphabet[s[i]].first==0){\n alphabet[s[i]].first++;\n alphabet[s[i]]... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n string_view view = s;\n unordered_map<char, string_view::const_iterator> unique;\n int max_unique = 0;\n int current_count = 0;\n auto left = view.begin();\n auto right = view.end() - 1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) { \n unordered_map<char, pair<int, int>> map;\n string longest = \"\";\n string strs = \"\";\n\n for(int i = 0; i<s.length(); i++) {\n if(map.find(s[i]) != map.end()) {\n if(strs.leng... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int big_one=0;\n int n=0;\n int size;\n string sub;\n if (s.size()==1){return 1;}\n else if (s.size()>1000){return 95;}\n for (int i = 0;i<s.size();i++){\n for (int j=0;j<s.... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int max = 0;\n\n list<char> characters;\n\n for (int i = 0; i < s.size(); i++) {\n bool repeat = false;\n for (auto o : characters) {\n if (o == s.at(i)) {\n repeat = true;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n list<char> a;\n int p=0;\n int c=0,k=0;\n for(int i=0;i<s.size();i++)\n {\n \n if(find(a.begin(),a.end(),s[i])==a.end())\n {\n a.push_back(s[i]);\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n\tint lengthOfLongestSubstring(string s) {\n\t\tint ctr_ret = 0;\n\t\tint ctr_tmp = 0;\n\t\tint string_size = s.size();\n\t\tlist<char> used_char;\n\t\tfor(int j=0; j<string_size; j++)\n\t\t{\n\t\t\tfor(int i=j; i<string_size; i++)\n\t\t\t{\n\t\t\t\tbool repeated = false;\n\t\t\t... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n if(s.length()==0){\n return 0;\n }\n unordered_set<char> arr;\n for(int i=0;i<s.length();i++){\n arr.insert(s[i]);\n }\n for(int i=arr.size()-1;i>=0;i--){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n if(s.length()==0){\n return 0;\n }\n unordered_set<char> arr;\n for(int i=0;i<s.length();i++){\n arr.insert(s[i]);\n }\n for(int i=arr.size()-1;i>=0;i--){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isCharacterExist(unordered_map<char,int> vis, char ch) {\n if (vis.find(ch) == vis.end()) return false;\n return true;\n }\n\n int lengthOfLongestSubstring(string s) {\n queue<char> q;\n int answer = 0;\n unordered_map<char, int> ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int substrL = 0;\n \n map<char, int> charsCount;\n for (int i = 0; i < s.length(); i++) {\n if (charsCount[s[i]] == 0) {\n substrL++;\n }\n\n charsCount[s[i]... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isDistinct(const std::string& s, int first, int last) {\n vector<bool> table(256);\n for (int i = first; i < last; ++i) {\n if (table[s[i]]) {\n return false;\n }\n\n table[s[i]] = true;\n }\n\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int len = 0;\n string str = \"\";\n list <char> letters;\n for(int i = 0; i < s.length(); i++) {\n int j = i;\n int templen = 0;\n string tempstr = \"\";\n while... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int i=0;\n int n=s.size();\n int maxlen=0;\n while(i<n)\n {\n unordered_map<char,int> mpp;\n bool flag=true;\n for(int j=i;j<n;j++)\n {\n i... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unsigned short result = 0;\n unsigned short counter = 0;\n\n unordered_map<char, unsigned short> existChar;\n for (unsigned short i = 0; i < s.length(); ++i){\n\n if (existChar.find(s[i]) == existChar.end()){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int p = 0;\n int max_count = 0;\n int start = 0;\n while(p<s.length()){\n unordered_map<char,int> m = {};\n while(p<s.length()){\n auto f = m.find(s[p]);\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size();\n if(n == 0) return n;\n int l = 0;\n int ans = 0;\n while(l < n){\n unordered_map<char, int> mp;\n int r = l;\n while(r < n){\n cha... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n unsigned short result = 0;\n unsigned short counter = 0;\n\n unordered_map<char, unsigned short> existChar;\n for (unsigned short i = 0; i < s.length(); ++i){\n\n if (existChar.find(s[i]) == existChar.end()){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n#include <unordered_map>\n\nstruct Window {\nWindow(char initial) {\n table[initial] = 0;\n}\n\nvoid udpate(char c) {\n auto it = table.find(c);\n int index = end++;\n if(it == table.end()) {\n table[c] = index;\n }\n else {\n begin = it->second + ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n int res = min(n, 1);\n int start = 0;\n if(res == 0) return 0;\n while(start < n){\n int end = start + 1;\n unordered_set<char> m;\n // unorder... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n int res = min(n, 1);\n int start = 0;\n if(res == 0) return 0;\n while(start < n){\n int end = start + 1;\n unordered_set<char> m;\n // unorder... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n\n\nint uni(unordered_map<char,int> m)\n{\n for(auto it: m)\n if(it.second>1)\n return false;\n return true;\n}\n \n\n int lengthOfLongestSubstring(string s) {\n unordered_map<char,int> m;\n int l=0,r=0,len=0;\n while(r<s.size())\n {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n\n\nint uni(unordered_map<char,int> m)\n{\n for(auto it: m)\n if(it.second>1)\n return false;\n return true;\n}\n \n\n int lengthOfLongestSubstring(string s) {\n unordered_map<char,int> m;\n int l=0,r=0,len=0;\n while(r<s.size())\n {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n if(n==0) return 0;\n int l = 0 ; \n int maxi = INT_MIN ;\n while(l<n){\n int r = l+1;\n int count = 1 ;\n vector<int> seen (500,0)... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isRepeated(vector<int> in)\n {\n for(int i=0;i<in.size();i++)\n {\n if(in[i]>1)\n return true;\n }\n return false;\n }\n int lengthOfLongestSubstring(string s)\n {\n vector<int> chs(256,0);\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isRepeated(vector<int> in)\n {\n for(int i=0;i<in.size();i++)\n {\n if(in[i]>1)\n return true;\n }\n return false;\n }\n int lengthOfLongestSubstring(string s)\n {\n vector<int> chs(256,0);\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n if(n==0 || n==1) return n;\n int maxSub = 0;\n \n for(int i=0;i<n;i++){\n string subStr = \"\";\n unordered_map<char,int> map;\n \n i... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int longest = 0;\n string curr;\n unordered_map<char, int> duplicates;\n\n for (int i = 0; i < s.size(); i++) {\n curr += s[i];\n\n if (duplicates.find(s[i]) != duplicates.end()) {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n\n unordered_map<char,int> posMap;\n\n for(int i=0; i< s.length(); i++)\n {\n posMap[s[i]] =i;\n }\n\n int maxLength =0;\n\n for(int i=0; i< s.length() && maxLength < s.length() - i... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "#pragma GCC optimize(\"Ofast,unroll-loops\")\n#pragma GCC target(\"avx2\")\nstatic auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n int numberOfBeams(std::vector<std::string>& bank) {\... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& b) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int r = 0, p = 0, l = 0, s = b[0].size() - 1;\n for (int i = b.size() - 1; i != -1; --i) {\n l = 0;\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& b){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int r=0,p=0,l=0,s=b[0].size()-1;\n for(int i =b.size()-1;i!=-1;--i)\n {\n l=0;\n for(int j=s;j!=-1;--... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& b) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int r = 0, p = 0, l = 0, s = b[0].size() - 1;\n for (int i = b.size() - 1; i != -1; --i) {\n l = 0;\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int ans = 0;\n int prev_row = 0;\n for (const string& row: bank) {\n int laser_c = 0;\n for (const char& slot: row) {\n laser_c += int(slot == '1');\n }\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int count_one(const string& s) {\n int ans = 0;\n for (char c : s) {\n if (c == '1') {\n ans++;\n }\n }\n return ans;\n }\n \n int numberOfBeams(vector<string>& bank) {\n int count = 0;\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int res = 0, prev = 0;\n for (const auto& row : bank) {\n int curr = 0;\n for (const auto& c : row) curr += c - '0';\n if (curr > 0) {\n res += prev * curr;\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int prev_devices = 0;\n bool f = 0;\n int beams = 0;\n for(int i=0; i<bank.size(); i++){\n int new_devices = 0;\n for(int j=0; j<bank[i].size(); j++){\n if(bank[i][j]=... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "/*\n\nhttps://leetcode.com/problems/number-of-laser-beams-in-a-bank/discuss/1660943/Python3-Java-C%2B%2B-Simple-O(mn)\n\nhttps://leetcode.com/problems/number-of-laser-beams-in-a-bank/discuss/1674079/Skip-and-Multiply\n\n*/\n\nclass Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 0 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int ans=0;\n int n=0;\n for(int i=0;i<bank.size();i++){\n int m=0;\n \n for(int j=0;j<bank[i].size();j++){\n if(bank[i][j]=='1') m++;\n }\n \n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 1 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int n = bank.size();\n vector<int>devices(n);\n\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<bank[i].length();j++)\n {\n devices[i]+=(bank[i][j] == '1');\n }\... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 1 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) \n {\n int ans=0;\n vector<int> arr;\n for(int i=0;i<bank.size();i++)\n {\n int c=0;\n for(int j=0;j<bank[i].size();j++)\n {\n if(bank[i][j]=='1')\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 1 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n vector<int> vec;\n for(int i = 0; i < bank.size(); i++) {\n int c = 0;\n for(int j = 0; j < bank[i].size(); j++) {\n if(bank[i][j] == '1') c++;\n }\n if(c != 0... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 1 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n\n int l = bank.size();\n vector<int> v;\n for(int i = 0 ; i < l ; i++)\n {\n int l2 = bank[i].length();\n int count = 0;\n for(int j = 0 ; j < l2 ; j++)\n {\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int n = bank.size();\n int m = bank[0].size();\n int ans = 0;\n vector<int> hash(n,0);\n for (int i = 0; i < n; i++) {\n int ones = 0;\n for (char it:bank[i]) {\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int m = bank.size();\n int n = bank[0].size();\n\n vector<int> rows(m, 0);\n\n for(int i = 0; i < m; i++)\n for(int j = 0; j < n; j++)\n if(bank[i][j] == '1')\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n vector<int> devices;\n for(int i = 0; i < bank.size(); i++){\n int counter = 0;\n for(int j = 0; j < bank[i].length(); j++){\n if(bank[i][j] == '1'){\n counter++;... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n vector<int> devices;\n for(int i = 0; i < bank.size(); i++){\n int counter = 0;\n for(int j = 0; j < bank[i].length(); j++){\n if(bank[i][j] == '1'){\n counter++;... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n unordered_map<int,int>mp;\n int res=0;\n int n=bank.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<bank[i].size();j++){\n if(bank[i][j]-48==1)mp[i]++;\n }\n }\n for(int i=0;i<n;i++){... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n unordered_map<int,int>mp;\n int res=0;\n int n=bank.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<bank[i].size();j++){\n if(bank[i][j]-48==1)mp[i]++;\n }\n }\n int x=0;\n for(in... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n map<int, int> lasers_per_row;\n int lasers = 0;\n int count = 0;\n int prev = 0;\n\n for(int i = 0; i < bank.size(); i++){\n for(int j = 0; j < bank[i].size(); j++){\n if(... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n unordered_map<int,int>mp;\n int res=0;\n int n=bank.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<bank[i].size();j++){\n if(bank[i][j]-48==1)mp[i]++;\n }\n }\n for(int i=0;i<n;i++){... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n unordered_map<int,int>mp;\n int res=0;\n int n=bank.size();\n for(int i=0;i<n;i++){\n for(int j=0;j<bank[i].size();j++){\n if(bank[i][j]-48==1)mp[i]++;\n }\n }\n for(int i=0;i<n;i++){... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& nums) \n {\n int m=nums.size();\n int n=nums[0].size();\n vector<int>v;\n for(auto & x:nums)\n { \n int c=0;\n sort(x.rbegin(),x.rend());\n for(auto & y:x)\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int getNumberOfOnes(string& bank) {\n int res = 0;\n for (int i = 0; i < bank.size(); i++)\n if (bank[i] == '1')\n res++;\n\n return res;\n }\n int numberOfBeams(vector<string>& bank) {\n int res = 0;\n pair<s... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int finalAns=0;\n int i=0;\n while(i<bank.size())\n {\n if(bank[i].find('1')<bank[i].length())\n {\n string str=bank[i];\n int cnt=count(str.begin(),str... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n ios_base::sync_with_stdio(false);\n int res = 0, prev = 0;\n for(string s : bank){\n int cnt = 0;\n for(char c: s){\n if(c == '1') cnt += 1;\n }\n if(cn... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int i=0;\n int sum=0;\n int cnt1=0;\n while(i<bank.size() && !cnt1){\n string str1 = bank[i];\n for(int l=0... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int i=0;\n int sum=0;\n int cnt1=0;\n while(i<bank.size() && !cnt1){\n string str1 = bank[i];\n for(int l=0;l<str1.size();l++){\n if(str1[l]=='1'){... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int i=0;\n int sum=0;\n int cnt1=0;\n while(i<bank.size() && !cnt1){\n string str1 = bank[i];\n for(int l=0... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int i=0;\n int sum=0;\n int cnt1=0;\n while(i<bank.size() && !cnt1){\n string str1 = bank[i];\n for(int l=0... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int res = 0;\n int prev = 0;\n for(auto row : bank){\n int count = 0;\n for(auto i : row){\n if(i == '1'){\n ++count;\n }\n }\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int sum = 0;\n int cnt1 = 0;\n for (auto s : bank) {\n int cnt2 = 0;\n for (auto c : s)\n cnt2 += (c == '1');\n if (cnt2) {\n sum += cnt1 * cnt2;\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int aura=0,tempAura=0;\n for (string i:bank){\n int ones=0;\n for (char j:i) ones+=j-'0';\n cout<<ones;\n if(ones){\n aura+=tempAura*ones;\n tem... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int ans = 0, lastRowDevices = 0;\n for(auto row: bank)\n {\n int curRowDevices = 0;\n for(auto col: row)\n {\n curRowDevices += (col == '1');\n }\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n\n int count (string &s) {\n int c=0;\n for (auto b:s) {\n c = c + b - '0';\n }\n return c;\n }\n\n int numberOfBeams(vector<string>& bank) {\n vector<int> devices;\n for (auto row:bank) {\n devices.push_back... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 2 | {
"code": "class Solution {\npublic:\n\n int count (string &s) {\n int c=0;\n for (auto b:s) {\n c = c + b - '0';\n }\n return c;\n }\n\n int numberOfBeams(vector<string>& bank) {\n vector<int> devices;\n for (auto row:bank) {\n devices.push_back... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 3 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) {\n int n = bank.size();\n vector<int> ans1;\n for(int i=0; i<n; i++){\n int count = 0;\n string ans = bank[i];\n for(int j=0; j<ans.length(); j++){\n if(ans[j]=='1'){\n count = count + 1;\... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 3 | {
"code": "class Solution {\npublic:\n\n int countDevices(string&binary){\n int c = 0;\n for(auto b: binary)\n c += b - '0';\n return c;\n }\n int numberOfBeams(vector<string>& bank) {\n vector<int>devices;\n for(auto row:bank)\n devices.push_back(countDev... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 3 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& bank) \n {\n vector<int> devices;\n for(string s : bank)\n {\n int count = 0;\n for(char c : s)\n {\n if(c == '1')\n count++;\n }\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 3 | {
"code": "class Solution\n{\npublic:\n // T.C.=O(n^2),S.C.=O(n)\n int countDevices(string &row)\n {\n int count = 0;\n for (int i = 0; i < row.size(); i++)\n {\n if (row[i] == '1')\n {\n count++;\n }\n }\n return count;\n ... |
2,244 | <p>Anti-theft security devices are activated inside a bank. You are given a <strong>0-indexed</strong> binary string array <code>bank</code> representing the floor plan of the bank, which is an <code>m x n</code> 2D matrix. <code>bank[i]</code> represents the <code>i<sup>th</sup></code> row, consisting of <code>'0&... | 3 | {
"code": "class Solution {\npublic:\n int numberOfBeams(vector<string>& b) {\n if(b.size()==1)return 0;\n vector<int>v;\n for(int i=0;i<b.size();i++){\n string a=b[i];\n int c = count(a.begin(), a.end(), '1');\n v.push_back(c);\n }\n vector... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n #pragma GCC optimise(\"03... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "#pragma GCC optimise(\"03\", \"unroll-loops\")\nint init = [] {\n ofstream(\"user.out\", ios::out)\n << \"6\\n7\\n100001\\n182\\n158\\n130\\n66\\n165\\n186\\n168\\n181\\n166\\n173\\n3\\n1\"\n \"00001\\n2\\n100001\\n200000\\n5\\n3\\n938\\n983\\n933\\n975\\n910\\n18619\\n197\"\n ... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,236 | <p>In a linked list of size <code>n</code>, where <code>n</code> is <strong>even</strong>, the <code>i<sup>th</sup></code> node (<strong>0-indexed</strong>) of the linked list is known as the <strong>twin</strong> of the <code>(n-1-i)<sup>th</sup></code> node, if <code>0 <= i <= (n / 2) - 1</code>.</p>
<ul>
<li... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\n publi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.