# [LeetCode]#1822. Sign of the Product of an Array

Environment: Python 3.8

Key technique: for, if

There is a function `signFunc(x)` that returns:

• `-1` if `x` is negative.
• `0` if `x` is equal to `0`.

You are given an integer array `nums`. Let `product` be the product of all values in the array `nums`.

Return `signFunc(product)`.

Example 1:

`Input: nums = [-1,-2,-3,-4,3,2,1]Output: 1Explanation: The product of all values in the array is 144, and signFunc(144) = 1`

Analysis:

1. ans=ans x nums[i] by using loop
2. if ans >0, return 1
3. if ans <0, return -1
4. if ans==0, return 0

Solution:

`class Solution:    def arraySign(self, nums):        ans=1        for i in range(len(nums)):            ans=ans*nums[i]        if ans >0:            return 1        if ans <0:            return -1        if ans ==0:            return 0`

Submissions:

# [LeetCode]#2124. Check if All A’s Appears Before All B’s

Environment: Python 3.8

Key technique: if

Given a string `s` consisting of only the characters `'a'` and `'b'`, return `true` if every `'a'` appears before every `'b'` in the string. Otherwise, return `false`.

Example 1:

`Input: s = "aaabbb"Output: trueExplanation:The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.Hence, every 'a' appears before every 'b' and we return true.`

Analysis:

1. If yes, return False. Else, return True.

Solution:

`class Solution:    def checkString(self, s):        if "ba" in s:            return False        else:            return True`

Submissions:

# [LeetCode]#2119. A Number After a Double Reversal

Environment: Python 3.8

Key technique: str(), int()

Reversing an integer means to reverse all its digits.

Given an integer `num`, reverse `num` to get `reversed1`, then reverse `reversed1` to get `reversed2`. Return `true` if `reversed2` equals `num`. Otherwise return `false`.

Example 1:

`Input: num = 526Output: trueExplanation: Reverse num to get 625, then reverse 625 to get 526, which equals num.`

Analysis:

1. Convert it to int format.
2. Convert it to a string format and reverse it.
3. If input equal converted result, return pass.
4. Else, return Fail.

Solution:

`class Solution:    def isSameAfterReversals(self, num):        temp=str(num)        temp=int(temp[::-1])        temp=str(temp)        temp=temp[::-1]        if int(temp) ==num:            return True        else:            return False`

Submissions:

# [LeetCode]#2114. Maximum Number of Words Found in Sentences

Environment: Python 3.8

Key technique: split

A sentence is a list of words that are separated by a single space with no leading or trailing spaces.

You are given an array of strings `sentences`, where each `sentences[i]` represents a single sentence.

Return the maximum number of words that appear in…

# [LeetCode]#2068. Check Whether Two Strings are Almost Equivalent

Environment: Python 3.8

Key technique: Counter, |, max

Two strings `word1` and `word2` are considered almost equivalent if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is at most `3`.

Given two strings `word1` and `word2`, each of length `n`, return `true`

# [LeetCode]#2108. Find First Palindromic String in the Array

Environment: Python 3.8

Key technique: for, [::-1]

Given an array of strings `words`, return the first palindromic string in the array. If there is no such string, return an empty string `""`.

A string is palindromic if it reads the same forward and backward.

Example 1:

`Input: words = ["abc","car","ada","racecar","cool"]Output: "ada"Explanation: The first string that is palindromic is "ada".Note that "racecar" is also palindromic, but it is not the first.`

Analysis:

1. If string == reversed string, return it.
2. If no string and reversed string is equal, return ‘’

Solution:

`class Solution:    def firstPalindrome(self, words):        for i in words:            if i==i[::-1]:                return i        return ''`

Submissions:

Reference:

https://leetcode.com/problems/find-first-palindromic-string-in-the-array/discuss/1639462/Python-99-faster-Simple-Solution

# [LeetCode]#2042. Check if Numbers Are Ascending in a Sentence

Environment: Python 3.8

Key technique: split, isdecimal, for, if, append

A sentence is a list of tokens separated by a single space with no leading or trailing spaces. …

# [LeetCode]#2103. Rings and Rods

Environment: Python 3.8

Key technique: set, if, for

There are `n` rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from `0` to `9`.

You are given a string `rings` of length `2n` that describes the `n` rings that are placed…

# [LeetCode]#2078. Two Furthest Houses With Different Colors

Environment: Python 3.8

Key technique: enumerate, if

There are `n` houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array `colors` of length `n`, where `colors[i]` represents the color of the `ith` house.

Return the maximum distance between two houses…

# [LeetCode]#2085. Count Common Words With One Occurrence

Environment: Python 3.8

Key technique: set, list

Given two string arrays `words1` and `words2`, return the number of strings that appear exactly once in each of the two arrays.

Example 1:

`Input: words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]Output: 2Explanation:- "leetcode" appears exactly once in each of the two arrays. We…`

## Fatboy Slim

Interesting in any computer science.

Get the Medium app