LintCode: Max of 3 Numbers

Max of 3 Numbers



Similar Problems:


Description
Given 3 integers, return the max of them.

Example

Given num1 = 1, num2 = 9, num3 = 0, return 9.

Github: code.dennyzhang.com

Credits To: lintcode.com

Leave me comments, if you have better ways to solve.


  • Solution:
// Blog link: https://code.dennyzhang.com/max-of-3-numbers
// Basic Ideas:
// Complexity: Time O(1), Space O(1)
/**
 * @param num1: An integer
 * @param num2: An integer
 * @param num3: An integer
 * @return: an interger
 */
func maxOfThreeNumbers (num1 int, num2 int, num3 int) int {
    res := num1
    if num2>res { res = num2 }
    if num3>res { res = num3 }
    return res
}
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.