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:

init ans=1

ans=ans x nums[i] by using loop

if ans >0, return 1

if ans <0, return -1

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

Given a string s consisting of only the characters 'a' and 'b', return trueif 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:

check pattern “ba” is matched with s.

If yes, return False. Else, return True.

Solution:

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

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:

Reverse input string

If string == reversed string, return it.

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 ''