Leetcode - 15. 3Sum
DescriptionGiven an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. 12345678910Example 1:Input: nums = [-1,0,1,2,-1,-4]Output: [[-1,-1,2],[-1,0,1]]Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.The distinct triplets are [...
Leetcode - 14. Longest Common Prefix
DescriptionWrite a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. 1234Example 1:Input: strs = ["flower","flow","flight"]Output: "fl" 12345Example 2:Input: strs = ["dog","racecar","car"]Output: ""Explanation: There is no common prefix among the input strings. 12345Constraints:1 <= strs.length <= 2000 <= strs[i].length ...
Leetcode - 13. Roman to Integer
DescriptionRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.12345678Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from left to right. Howeve...
Leetcode - 12. Integer to Roman
DescriptionSeven different symbols represent Roman numerals with the following values: Symbol ValueI 1V 5X 10L 50C 100D 500M 1000Roman numerals are formed by appending the conversions of decimal place values from highest to lowest. Converting a decimal place value into a Roman numeral has the following rules: If the value does not start with 4 or 9, select the symbol of the maximal value that can be subtracted from the input, append that symbol to the result, subtract...
Network layer
Network layerThe network layer is responsible for delivering packets from the source host to the destination host across multiple networks. Its main functions include logical addressing, routing, forwarding, and error handling. It also supports different service models such as virtual circuit and datagram service. Network ServicesVirtual Circuit vs Datagram Service Virtual Circuit: A pre-established path between source and destination. It provides reliability and order but requires setup over...
Leetcode - 10. Regular Expression Matching
DescriptionGiven an input string s and a pattern p, implement regular expression matching with support for ‘.’ and ‘*’ where: ‘.’ Matches any single character.‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string (not partial). Example 1:123Input: s = "aa", p = "a"Output: falseExplanation: "a" does not match the entire string "aa".Example 2:123Input: s = "aa", p = "a*"Output: trueExpl...
Leetcode - 9. Palindrome Number
DescriptionGiven an integer x, return true if x is a palindrome, and false otherwise. Example 1:123Input: x = 121Output: trueExplanation: 121 reads as 121 from left to right and from right to left.Example 2:123Input: x = -121Output: falseExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.Example 3:123Input: x = 10Output: falseExplanation: Reads 01 from right to left. Therefore it is not a palindrome. 123Constraints:-231 <= ...
large language model
ReferencesDive Into Deep Learning Create Environmentuse conda or miniconda123conda env remove d2l-zhconda create -n d2l-zh -y python=3.8 pipconda activate d2l-zh install dependencies1pip install jupyter d2l torch torchvision download d2l-zh.zip123wget http://zh-v2.d2l.ai/d2l-zh.zipunzip d2l-zh.zipjupyter notebook
Leetcode - 7. Reverse Integer
DescriptionGiven a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2^31, 2^31 - 1], then return 0. Example 1: 12Input: x = 123Output: 321 Example 2: 12Input: x = -123Output: -321 Example 3: 12Input: x = 120Output: 21 Example 4: 12Input: x = 0Output: 0 Constraints: -2^31 <= x <= 2^31 - 1 Approach1234567891011121314151617class Solution: def reverse(self, x: int) -> int: sign = -1 if ...
Leetcode - 8. String to Integer (atoi)
DescriptionImplement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for myAtoi(string s) is as follows: Whitespace: Ignore any leading whitespace (“ “). Signedness: Determine the sign by checking if the next character is ‘-‘ or ‘+’, assuming positivity if neither present. Conversion: Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the resul...






