# [Study][Python] lambda

This is a note for python study.

The Lambda can use a function by one line code.

For example, below add function is two lines as below.

return x+y

We can re-write one line as below.

The result is the same.

# [crypto] Crypto exchange

In recent months, I join the crypto investigation. Below is my crypto exchange list.

1. Max exchange

If you use TWD, you can buy USDT and send them to other exchange to buy other coins such as BTC, ETH… This is for rookie.

Staking Max coin apy is 2% to 5%.

2. Binance

# [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 positive.
• -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: 1
Explanation: The product of all values in the array is 144, and signFunc(144) = 1

Analysis:

1. init ans=1
2. ans=ans x nums[i] by using loop
3. if ans >0, return 1
4. if ans <0, return -1
5. 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: true
Explanation:
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. check pattern “ba” is matched with s.
2. 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.

• For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.

Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. 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: