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...
Leetcode - 11. Container With Most Water
DescriptionYou are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. Example 1:123Input: height = [1,8,6,2,5,4,8,3,7]Output: 49Explanation: The above vertical lines are represented ...
large language model
Large Language ModelDefinitionA large language model is a machine learning model that is trained on a large corpus of text data, such as Wikipedia or the Web. These models can generate high-quality text that is similar to the training data, but can also generate text that is not present in the training data. History < 1990s: IBM’s statistical language model (SLM) 1990s-2000s: Neural language models (NLLMs) 2001s: n-gram model 2010s: GPT-2, GPT-3 Dataset PreprocessingTokenizationSplitting ...
Leetcode - 6. Zigzag Conversion
DescriptionThe string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 123P A H NA P L S I I GY I R Write the code to convert a string to a zigzag pattern. You should do it in-place. Example 1: 12Input: s = "PAYPALISHIRING", numRows = 3Output: "PAHNAPLSIIGYIR" Example 2: 1234567Input: s = "PAYPALISHIRING", numRows = 4Output: "...
Leetcode - 6. Longest Palindromic Substring
DescriptionGiven a string s, return the longest palindromic substring in s. Example 1:123Input: s = "babad"Output: "bab"Explanation: "aba" is also a valid answer.Example 2:12Input: s = "cbbd"Output: "bb"1234Constraints:1 <= s.length <= 1000s consist of only digits and English letters. Approach: Expand Around Center1234567891011121314151617181920212223class Solution: def longestPalindrome(self, s: str) -> str: if not s or len...
Graph
GraphA graph is a data structure that consists of a set of nodes (also called vertices) and a set of edges that connect pairs of nodes. Graphs can be directed or undirected, depending on whether the edges have a direction associated with them. They are used to represent various types of relationships and connections, such as social networks, transportation systems, and communication networks. Types of Graphs Directed Graph (Digraph): A graph where each edge has a direction, indicating a one-w...
Leetcode - 5. Median of Two Sorted Arrays
DescriptionGiven two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1:123Input: nums1 = [1,3], nums2 = [2]Output: 2.00000Explanation: merged array = [1,2,3] and median is 2.Example 2:123Input: nums1 = [1,2], nums2 = [3,4]Output: 2.50000Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5. 12345678Constraints:nums1.length == mnums2.length == n0 <= m <=...






