Environment: Python 3.8
Key technique: for, if
There is a function signFunc(x)
that returns:
1
ifx
is positive.-1
ifx
is negative.0
ifx
is equal to0
.
You are given an integer array nums
. Let product
be the product of all values in the array nums
.
…
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…
Environment: Python 3.8
Key technique: str(), int()
Reversing an integer means to reverse all its digits.
- For example, reversing
2021
gives1202
. Reversing12300
gives321
as the leading zeros are not retained.
Given an integer num
, reverse num
to get reversed1
, then reverse reversed1
to get reversed2
. Return true
…
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…