Find the focal length of the spherical mirror with the given radius-of-curvature R.
NOTE
The focal length of the 'convex' mirror floor(-R/2) and that of the 'concave' mirror is floor(R/2).
Example 1:
Input: type = "concave", R = 5.4
Output: 2
Explanation: Focal length of concave mirror = floor(R/2) = floor(5.4/2) = floor(2.7) = 2.
Example 2:
Input: type = "convex", R = 10
Output: -5
Explanation: Focal length of convex mirror = floor(-R/2) = floor(-10/2) = floor(-5) = -5.
Your Task:
You don't need to read or print anything. Your task is to complete the function findFocalLength() which takes R and type as input parameters and returns the floor value of focal length.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
Constraints:
1 <= R <= 100

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

	def findFocalLength(self, R, type):

		# Code here

Solutions:
class Solution:

	def findFocalLength(self, R, type):
		if type == 'concave':
			return int(R // 2)
		else:
			return int(-R // 2)


import math

class Solution:

	def findFocalLength(self, R, type):
		if type == 'convex':
			return math.floor(-R / 2)
		return math.floor(R / 2)


import math

class Solution:

	def findFocalLength(self, R, type):
		if type == 'concave':
			return math.floor(R / 2)
		else:
			return math.floor(-R / 2)


class Solution:

	def findFocalLength(self, R, type):
		if type == 'concave':
			n = int(R // 2)
			return n
		elif type == 'convex':
			m = int(-R // 2)
			return m


class Solution:

	def findFocalLength(self, R, type):
		if type == 'convex':
			f_length = -R // 2
		if type == 'concave':
			f_length = R // 2
		return int(f_length)


class Solution:

	def findFocalLength(self, R, type):
		if type == 'concave':
			return int(R / 2)
		else:
			k = float(-R / 2)
			z = k - 1
			if R % 2 != 0:
				return int(z)
			else:
				return int(-R / 2)


class Solution:

	def findFocalLength(self, R, type):
		if type == 'convex':
			f = -R // 2
			return int(f)
		else:
			f = R / 2
			return int(f)


class Solution:

	def findFocalLength(self, R, type):
		from math import floor
		if type == 'concave':
			return int(R / 2)
		return floor(-R / 2)


class Solution:

	def findFocalLength(self, R, ty):
		if ty == 'convex':
			return int(-R // 2)
		return int(R // 2)


import numpy as np

class Solution:

	def findFocalLength(self, R, type):
		if type == 'concave':
			return int(np.floor(R / 2))
		else:
			return int(np.floor(-R / 2))


class Solution:

	def findFocalLength(self, R, type):
		if type == 'convex':
			res1 = -R // 2
			return int(res1)
		else:
			res2 = R // 2
			return int(res2)


import math

class Solution:

	def findFocalLength(self, R, type):
		int(R)
		if type == 'concave':
			leng = math.floor(R / 2)
			return int(leng)
		elif type == 'convex':
			leng = math.ceil(R / 2)
			return int(-leng)


class Solution:

	def findFocalLength(self, R, type):
		if type == 'concave':
			return int(R // 2)
		elif type == 'convex':
			return int(-1 * R // 2)