Given a range from low to high and a number K. The task is to count the number which has the unit digit equal to K. 
 
Example 1:
Input:
low = 4, high = 9, K = 4 
Output:
1
Explanation:
4 is the only number with 4 as the
unit digit in the range of (4,9).
Example 2:
Input:
low = 3, high = 35, K = 3 
Output:
4
Explanation:
3, 13, 23, and 33 are the only numbers
with 3 as the unit digit in the given range.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function countLastDigitK() which takes 3 Integers  low, high, and K as input and returns the answer.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= low <= high <= 10^{9}
0 <= K <= 9

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def countLastDigitK(self, low, high, K):

        # code here 

Solutions:
class Solution:

	def countLastDigitK(self, low, high, K):
		v = high // 10 - low // 10
		l = str(low / 10)[-1]
		h = str(high / 10)[-1]
		if int(l) > K:
			v -= 1
		if int(h) >= K:
			v += 1
		return v


class Solution:

	def countLastDigitK(self, low, high, K):
		count = 0
		if high - low < 10 and (low <= K and high >= K):
			return 1
		if low % 10 <= K:
			count += 1
		if high % 10 >= K:
			count += 1
		high = high - high % 10
		low = low + (10 - low % 10)
		count += (high - low) // 10
		return count