Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
romankurnovskii committed Apr 2, 2024
1 parent 95618e3 commit 1f855fe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
40 changes: 36 additions & 4 deletions static/search/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -5951,9 +5951,9 @@
},
{
"uri": "/tracks/algorithms-101/leetcode/hard/2444/",
"title": "Count Subarrays With Fixed Bounds",
"description": "Count Subarrays With Fixed Bounds",
"content": "\nLeetCode problem 2444\n\nclass Solution:\n def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int:\n j1 = j2 = k = -1\n res = 0\n for i, v in enumerate(nums):\n if v maxK:\n k = i\n if v == minK:\n j1 = i\n if v == maxK:\n j2 = i\n res += max(0, min(j1, j2) - k)\n return res\n\n`",
"title": "2444. Count Subarrays With Fixed Bounds",
"description": "2444. Count Subarrays With Fixed Bounds",
"content": "\nLeetCode problem 2444\n\nclass Solution:\n def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int:\n j1 = j2 = k = -1\n res = 0\n for i, v in enumerate(nums):\n if v maxK:\n k = i\n if v == minK:\n j1 = i\n if v == maxK:\n j2 = i\n res += max(0, min(j1, j2) - k)\n return res\n",
"tags": [],
"lang": "ru"
},
Expand Down Expand Up @@ -7416,6 +7416,14 @@
],
"lang": "ru"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/58/",
"title": "58. Length of Last Word",
"description": "58. Length of Last Word",
"content": "\nLeetCode problem 58\n\nclass Solution:\n def lengthOfLastWord(self, s: str) -> int:\n i = len(s) - 1\n while i >= 0 and s[i] == ' ':\n i -= 1\n j = i\n while j >= 0 and s[j] != ' ':\n j -= 1\n return i - j\n\nclass Solution:\n def lengthOfLastWord(self, s: str) -> int:\n ar = s.split()\n return len(ar[-1])\n",
"tags": [],
"lang": "ru"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/543/",
"content": "Definition for a binary tree node.\nclass TreeNode:\ndef init(self, val=0, left=None, right=None):\nself.val = val\nself.left = left\nself.right = right\nclass Solution:\n def diameterOfBinaryTree(self, root: TreeNode) -> int:\n diameter = [0]\n def dfs(root):\n if not root:\n return (0, 0)\n left = max(dfs(root.left))\n right = max(dfs(root.right))\n\n diameter[0] = max(diameter[0], left + right)\n return (left + 1, right + 1)\n\n dfs(root)\n return diameter[0]\n",
Expand Down Expand Up @@ -8499,6 +8507,14 @@
"tags": [],
"lang": "ru"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/205/",
"title": "205. Isomorphic Strings",
"description": "205. Isomorphic Strings",
"content": "\nLeetCode problem 205\n\nUse two dictionaries to track the mappings from s to t and from t to s. This helps in ensuring no two characters map to the same character.\n\nKey Idea**: To verify if two strings are isomorphic, we need to ensure that each character in s maps to a unique character in t, and vice versa. This bi-directional mapping is crucial to maintain the isomorphism property.\nData Structures**: Two hash maps (or dictionaries in Python) are ideal for maintaining these mappings efficiently.\n\nApproach\nInitial Checks: If the lengths of s and t are different, they cannot be isomorphic. Return false immediately.\nCreate Two Mappings: Initialize two dictionaries. One for mapping characters from s to t (s_to_t) and another from t to s (t_to_s).\nIterate Over Characters:\nFor each character pair (s_char, t_char) in s and t, check:\n If s_char maps to a different t_char in s_to_t, or t_char maps to a different s_char in t_to_s, return false.\n Update s_to_t[s_char] = t_char and t_to_s[t_char] = s_char.\nReturn True: If the loop completes without returning false, then s and t are isomorphic.\n\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n if len(s) != len(t):\n return False\n\n s_to_t, t_to_s = {}, {}\n\n for s_char, t_char in zip(s, t):\n if (s_char in s_to_t and s_to_t[s_char] != t_char) or \\\n (t_char in t_to_s and t_to_s[t_char] != s_char):\n return False\n s_to_t[s_char] = t_char\n t_to_s[t_char] = s_char\n\n return True\n`",
"tags": [],
"lang": "ru"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/2047/",
"title": "2047. Number of Valid Words in a Sentence",
Expand Down Expand Up @@ -17572,7 +17588,7 @@
"uri": "/tracks/algorithms-101/leetcode/hard/2444/",
"title": "2444. Count Subarrays With Fixed Bounds",
"description": "2444. Count Subarrays With Fixed Bounds",
"content": "\nLeetCode problem 2444\n\nclass Solution:\n def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int:\n j1 = j2 = k = -1\n res = 0\n for i, v in enumerate(nums):\n if v maxK:\n k = i\n if v == minK:\n j1 = i\n if v == maxK:\n j2 = i\n res += max(0, min(j1, j2) - k)\n return res\n`",
"content": "\nLeetCode problem 2444\n\nclass Solution:\n def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int:\n j1 = j2 = k = -1\n res = 0\n for i, v in enumerate(nums):\n if v maxK:\n k = i\n if v == minK:\n j1 = i\n if v == maxK:\n j2 = i\n res += max(0, min(j1, j2) - k)\n return res\n",
"tags": [],
"lang": "en"
},
Expand Down Expand Up @@ -19035,6 +19051,14 @@
],
"lang": "en"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/58/",
"title": "58. Length of Last Word",
"description": "58. Length of Last Word",
"content": "\nLeetCode problem 58\n\nclass Solution:\n def lengthOfLastWord(self, s: str) -> int:\n i = len(s) - 1\n while i >= 0 and s[i] == ' ':\n i -= 1\n j = i\n while j >= 0 and s[j] != ' ':\n j -= 1\n return i - j\n\nclass Solution:\n def lengthOfLastWord(self, s: str) -> int:\n ar = s.split()\n return len(ar[-1])\n",
"tags": [],
"lang": "en"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/543/",
"content": "Definition for a binary tree node.\nclass TreeNode:\ndef init(self, val=0, left=None, right=None):\nself.val = val\nself.left = left\nself.right = right\nclass Solution:\n def diameterOfBinaryTree(self, root: TreeNode) -> int:\n diameter = [0]\n def dfs(root):\n if not root:\n return (0, 0)\n left = max(dfs(root.left))\n right = max(dfs(root.right))\n\n diameter[0] = max(diameter[0], left + right)\n return (left + 1, right + 1)\n\n dfs(root)\n return diameter[0]\n",
Expand Down Expand Up @@ -20117,6 +20141,14 @@
"tags": [],
"lang": "en"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/205/",
"title": "205. Isomorphic Strings",
"description": "205. Isomorphic Strings",
"content": "\nLeetCode problem 205\n\nUse two dictionaries to track the mappings from s to t and from t to s. This helps in ensuring no two characters map to the same character.\n\nKey Idea**: To verify if two strings are isomorphic, we need to ensure that each character in s maps to a unique character in t, and vice versa. This bi-directional mapping is crucial to maintain the isomorphism property.\nData Structures**: Two hash maps (or dictionaries in Python) are ideal for maintaining these mappings efficiently.\n\nApproach\nInitial Checks: If the lengths of s and t are different, they cannot be isomorphic. Return false immediately.\nCreate Two Mappings: Initialize two dictionaries. One for mapping characters from s to t (s_to_t) and another from t to s (t_to_s).\nIterate Over Characters:\nFor each character pair (s_char, t_char) in s and t, check:\n If s_char maps to a different t_char in s_to_t, or t_char maps to a different s_char in t_to_s, return false.\n Update s_to_t[s_char] = t_char and t_to_s[t_char] = s_char.\nReturn True: If the loop completes without returning false, then s and t are isomorphic.\n\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n if len(s) != len(t):\n return False\n\n s_to_t, t_to_s = {}, {}\n\n for s_char, t_char in zip(s, t):\n if (s_char in s_to_t and s_to_t[s_char] != t_char) or \\\n (t_char in t_to_s and t_to_s[t_char] != s_char):\n return False\n s_to_t[s_char] = t_char\n t_to_s[t_char] = s_char\n\n return True\n`",
"tags": [],
"lang": "en"
},
{
"uri": "/tracks/algorithms-101/leetcode/easy/2047/",
"title": "2047. Number of Valid Words in a Sentence",
Expand Down
2 changes: 1 addition & 1 deletion static/search/lunr-index.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions static_files/leetcode-problems.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
"en": "https://romankurnovskii.com/en/tracks/algorithms-101/leetcode/easy/2880/"
}
},
"58": {
"difficulty": "Easy",
"languages": {
"ru": "https://romankurnovskii.com/ru/tracks/algorithms-101/leetcode/easy/58/",
"en": "https://romankurnovskii.com/en/tracks/algorithms-101/leetcode/easy/58/"
}
},
"2413": {
"difficulty": "Easy",
"languages": {
Expand Down Expand Up @@ -797,6 +804,13 @@
"en": "https://romankurnovskii.com/en/tracks/algorithms-101/leetcode/easy/2970/"
}
},
"205": {
"difficulty": "Easy",
"languages": {
"ru": "https://romankurnovskii.com/ru/tracks/algorithms-101/leetcode/easy/205/",
"en": "https://romankurnovskii.com/en/tracks/algorithms-101/leetcode/easy/205/"
}
},
"1957": {
"difficulty": "Easy",
"languages": {
Expand Down

0 comments on commit 1f855fe

Please sign in to comment.