Easy

Given an integer n, return the largest number that contains exactly n digits.

Example

For n = 2, the output should be
largestNumber(n) = 99.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    Guaranteed constraints:
    1 ≤ n ≤ 9.

  • [output] integer

    • The largest integer of length n.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int largestNumber(int n)
{
	int N=0;

	for(int i=0;i<n;i++)
	{
		N*=10;
		N+=9;
	}

	return N;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Seats in Theater  (0) 2020.04.07
<Codesignal> Candies  (0) 2020.04.07
<Codesignal> Add Two Digits  (0) 2020.04.07
<Codesignal> Sudoku  (0) 2020.04.06
<Codesignal> spiralNumbers  (0) 2020.04.06

+ Recent posts