leetcode 1603. 設計停車系統

請你給一個停車場設計一個停車系統。停車場總共有三種不同大小的車位:大,中和小,每種尺寸分別有固定數目的車位。

請你實現 ParkingSystem 類:

ParkingSystem(int big, int medium, int small) 初始化 ParkingSystem 類,三個參數分別對應每種停車位的數目。
bool addCar(int carType) 檢查是否有 carType 對應的停車位。 carType 有三種類型:大,中,小,分別用數字 1, 2 和 3 表示。一輛車只能停在 carType 對應尺寸的停車位中。如果沒有空車位,請返回 false ,否則將該車停入車位并返回 true 。

示例 1:

輸入:
[“ParkingSystem”, “addCar”, “addCar”, “addCar”, “addCar”]
[[1, 1, 0], [1], [2], [3], [1]]
輸出:
[null, true, true, false, false]

解釋:
ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
parkingSystem.addCar(1); // 返回 true ,因為有 1 個空的大車位
parkingSystem.addCar(2); // 返回 true ,因為有 1 個空的中車位
parkingSystem.addCar(3); // 返回 false ,因為沒有空的小車位
parkingSystem.addCar(1); // 返回 false ,因為沒有空的大車位,唯一一個大車位已經被占據了

代碼

    class ParkingSystem {int big,medium,small;public ParkingSystem(int big, int medium, int small) {this.big = big;this.medium = medium;this.small = small;}public boolean addCar(int carType) {if(carType==1)return --big>=0;else if(carType==2)return --medium>=0;else return --small>=0;}}/*** Your ParkingSystem object will be instantiated and called as such:* ParkingSystem obj = new ParkingSystem(big, medium, small);* boolean param_1 = obj.addCar(carType);*/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391585.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391585.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391585.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

IBM量子計算新突破:成功構建50個量子比特原型機

本文來自AI新媒體量子位(QbitAI)IBM去年開始以云計算服務的形式提供量子計算能力。當時,IBM發布了包含5個量子比特的計算機。在短短18個月之后,IBM周五宣布,將發布包含20個量子比特的計算機。 IBM還宣布,該…

ChromeDriver與chrome對應關系

http://chromedriver.storage.googleapis.com/index.html 轉載于:https://www.cnblogs.com/gcgc/p/11387605.html

快速排序和快速選擇(quickSort and quickSelect)算法

排序算法:快速排序(quicksort)遞歸與非遞歸算法 TopK問題:快速選擇(quickSelect)算法 import java.util.*; import java.lang.*;public class Demo {// 非遞歸 using stackpublic static void quickSortStack(int[] nums, int left, int right) {if (lef…

小程序點擊地圖氣泡獲取氣泡_氣泡上的氣泡

小程序點擊地圖氣泡獲取氣泡Combining two colors that are two steps apart on the Color Wheel creates a Diad Color Harmony. This Color Harmony is one of the lesser used ones. I decided to cover it here to add variety to your options for colorizing visualizati…

leetcode 150. 逆波蘭表達式求值(棧)

根據 逆波蘭表示法,求表達式的值。 有效的算符包括 、-、*、/ 。每個運算對象可以是整數,也可以是另一個逆波蘭表達式。 說明: 整數除法只保留整數部分。 給定逆波蘭表達式總是有效的。換句話說,表達式總會得出有效數值且不存在…

WebLogic常見問題

myeclipseweblogic10的配置,配置成功 運行中可能失敗,由于weblogic10不穩定,重啟機器后可以使用了 web工程使用到hibernate3時可能出現問題 ClassNotFoundException: org.hibernate.hql.ast.HqlToken 參考http://blog.chinajavaworld.com/ent…

PopTheBubble —測量媒體偏差的產品創意

產品管理 (Product Management) A couple of months ago, I decided to try something new. The MVP Lab by Mozilla is an 8-week incubator for pre-startup teams to explore product concepts and, over the 8 weeks of the program, ship a minimum viable product that p…

linux-Centos7安裝nginx

首先配置linux環境,我這里是剛剛裝好linux,所以一次性安裝了一系列我需要到的環境; yum install pcre pcre-devel zlib zlib-devel openssl openssl-devel gd gd-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel e…

javascript原型_JavaScript原型初學者指南

javascript原型You cant get very far in JavaScript without dealing with objects. Theyre foundational to almost every aspect of the JavaScript programming language. In fact, learning how to create objects is probably one of the first things you studied when …

leetcode 73. 矩陣置零

給定一個 m x n 的矩陣,如果一個元素為 0 ,則將其所在行和列的所有元素都設為 0 。請使用 原地 算法。 進階: 一個直觀的解決方案是使用 O(mn) 的額外空間,但這并不是一個好的解決方案。 一個簡單的改進方案是使用 O(m n) 的額…

elasticsearch,elasticsearch-service安裝

在Windows上安裝Elasticsearch.zip 1 安裝條件 安裝需具備java 8或更高版本;官方的Oracle發行版,只需安裝JDKElasticsearch的ZIP安裝包——安裝包地址 2 如何安裝 Elasticsearch 傻瓜式的點下一步即可, java 注意環境變量配置 3 如何判斷安裝…

圖表可視化seaborn風格和調色盤

seaborn是基于matplotlib的python數據可視化庫,提供更高層次的API封裝,包括一些高級圖表可視化等工具。 使用seaborn需要先安裝改模塊pip3 install seaborn 。 一、風格style 包括set() / set_style() / axes_style() / despine() / set_context() 創建正…

面向Tableau開發人員的Python簡要介紹(第3部分)

用PYTHON探索數據 (EXPLORING DATA WITH PYTHON) One of Tableau’s biggest advantages is how it lets you swim around in your data. You don’t always need a fine-tuned dashboard to find meaningful insights, so even someone with quite a basic understanding of T…

leetcode 191. 位1的個數(位運算)

編寫一個函數,輸入是一個無符號整數(以二進制串的形式),返回其二進制表達式中數字位數為 ‘1’ 的個數(也被稱為漢明重量)。 提示: 請注意,在某些語言(如 Java&#xf…

7、芯片發展

第一臺繼電器式計算機由康德拉.楚澤制造(1910-1995),這臺機器使用了二進制數,但早期版本中使用的是機械存儲器而非繼電器,使用老式35毫米電影膠片進行穿孔編程。 同一時期,哈佛大學研究生霍華德.艾肯 要尋找…

seaborn分布數據可視化:直方圖|密度圖|散點圖

系統自帶的數據表格(存放在github上https://github.com/mwaskom/seaborn-data),使用時通過sns.load_dataset(表名稱)即可,結果為一個DataFrame。 print(sns.get_dataset_names()) #獲取所有數據表名稱 # [anscombe, attention, …

如何成為一個優秀的程序員_如何成為一名優秀的程序員

如何成為一個優秀的程序員by Amy M Haddad通過艾米M哈達德(Amy M Haddad) 如何成為一名優秀的程序員 (How to be a great programmer) What sets apart the really great programmers?是什么使真正出色的程序員與眾不同? As we all know, great programmers buil…

pymc3使用_使用PyMC3了解飛機事故趨勢

pymc3使用Visually exploring historic airline accidents, applying frequentist interpretations and validating changing trends with PyMC3.使用PyMC3直觀地瀏覽歷史性航空事故,應用常識性解釋并驗證變化趨勢。 前言 (Preface) On the 7th of August this yea…

視頻監控業務上云方案解析

摘要:阿里云針對安防監控服務在傳統IT架構下面臨的上述問題,基于阿里云存儲服務,提供視頻監控解決方案。從2015年推出視頻監控存儲與播放解決方案以來,幫助大量的視頻監控企業解決了上云的過程中遇到的問題,針對不同的…

leetcode 341. 扁平化嵌套列表迭代器(dfs)

給你一個嵌套的整型列表。請你設計一個迭代器,使其能夠遍歷這個整型列表中的所有整數。 列表中的每一項或者為一個整數,或者是另一個列表。其中列表的元素也可能是整數或是其他列表。 示例 1: 輸入: [[1,1],2,[1,1]] 輸出: [1,1,2,1,1] 解釋: 通過重復…