【Lintcode】454. Rectangle Area

题目地址:

https://www.lintcode.com/problem/rectangle-area/description

设计一个矩形类,可以以长和宽为参数做初始化,并且可以返回其面积。代码如下:

public class Rectangle {
    /*
     * Define two public attributes width and height of type int.
     */
    // write your code here
    private int width, height;
    
    /*
     * Define a constructor which expects two parameters width and height here.
     */
    // write your code here
    public Rectangle(int width, int height) {
        this.width = width;
        this.height = height;
    }
    
    /*
     * Define a public method `getArea` which can calculate the area of the
     * rectangle and return.
     */
    // write your code here
    public int getArea() {
        return width * height;
    }
}

所有方法时空复杂度 O ( 1 ) O(1) O(1)

©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页