Title Description
Given a double base type and floating-point type int integer exponent. Seeking exponent of the power base.
Ensure the base and exponent are not simultaneously 0
Thinking
Seeking power base of the exponent, exponent there are two possibilities,
- exponent>0
- exponent for loop times and the results multiplied base
- exponent<0
- for circulation exponent times, and the result divided by base
Output;
# -*- coding:utf-8 -*- class Solution: def Power(self, base, exponent): # write code here resault = 1 if exponent>0: for i in range(0,exponent): resault = resault*base elif exponent<0: exponentabs = abs(exponent) for i in range(0,exponentabs): resault = resault/base return resault
Adjust the order of the array so that in front of the even-odd
Title Description
Enter an array of integers, to realize a function to adjust the order of the numbers in the array, such that all the odd part of the front half of the array, is located in the second half of all the even array, and between odd and ensure a relatively even, odd and even the same position.
This use python to do well:
# -*- coding:utf-8 -*- class Solution: def reOrderArray(self, array): # write code here ji = [] ou = [] for i in array: if i %2 ==0: ou.append(i) else: ji.append(i) return ji+ou