본문 바로가기

Algorithm/Leet Code

LeetCode #1189 MaximumNumberOfBalloons. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, 데..

LeetCode #1189 MaximumNumberOfBalloons. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, 데이터베이스, sql, query, 쿼리

 

 

Runtime: 0 ms, faster than 100.00% of C++ online submissions for Maximum Number of Balloons.

 

Memory Usage: 8.9 MB, less than 100.00% of C++ online submissions for Maximum Number of Balloons.

 

 

 

LeetCode #1189

Q.

 Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.

 

 You can use each character in text at most once. Return the maximum number of instances that can be formed.

 

 

 주어진 문자열에서, "balloon" 이라는 문자의 객체를 가능한한 많이 만들고 싶다.

 

문자열에서 각 문자는 한번만 쓸 수 있다. 최대한 만들수 있는 개수를 반환해라.

 

 

 

Example 1:

Input: text = "nlaebolko"

Output: 1

 

 

 

Example 2:

Input: text = "loonbalxballpoon"

Output: 2

 

 

 

Example 3:

 

Input: text = "leetcode"

Output: 0

 

 

 

 

Constraints:

  • 1 <= text.length <= 10^4
  • text consists of lower case English letters only.

 

 

 

Process

// Process
//1. Input text string
//2. Make lowercaseTable
//3. Fill the table in with count
//4. Count balloon string
//5. Return count

 

 

// 처리과정

//1. 문자열을 입력받는다.

//2. 소문자 테이블 준비한다.

//3. 문자열에서 소문자테이블을 채워넣는다.

//4. 만들 수 있는 balloon 문자 수를 센다.

//5. 수를 반환한다.

 

 

 

Code.. lemme see example code!!!

코드.. 예제코드를 보자!!!

 

 

 

class Solution {
public:
	int maxNumberOfBalloons(string text) {
        int resultCount = 0;
        
		//2.
		vector<int> alphabetTable;
		for (int i = 0; i < 26; ++i) {
			alphabetTable.push_back(0);
		}

		//3.
		for (int i = 0; i < text.length(); ++i) {
			++alphabetTable[text[i] - 97];
		}

		//4. 
        bool isDone = false;
		while (!isDone) {
            if (alphabetTable[0]-- > 0 && alphabetTable[1]-- > 0
               && alphabetTable[11]-- > 1 && alphabetTable[14]-- > 1
               && alphabetTable[13]-- > 0) 
            {
                ++resultCount;
                --alphabetTable[11];
                --alphabetTable[14];
            } else {
                isDone = true;
            }
        }
        return resultCount;
	}
};

 

 

 

Something else you might like...?

 

 

2019/12/19 - [Algorithm/Leet Code] - LeetCode #706 DesignHashMap. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, 데이터베이..

2019/12/11 - [Algorithm/Leet Code] - LeetCode #1047 RemoveAllAdjacentDuplicatesInString. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술..

2019/12/06 - [Algorithm/Leet Code] - LeetCode #844 BackspaceStringCompare. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, 데이..

 

 

 

2019/11/02 - [Algorithm/Code Fights (Code Signal)] - CodeSignal Intro Databases #7 MostExpensive. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, ..

2019/10/31 - [Algorithm/Code Fights (Code Signal)] - CodeSignal Intro Databases #6 VolleyballResults. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면..

 

 

2019/08/14 - [Life/Item review] - Mi Band 4 review, 미밴드4 후기, 장점, 단점, 리뷰, 한글, global review, 미밴드4 글로벌 후기, 리뷰, 구매, 사용방법, setting, 세팅, ProsNCons

 

 

2018/10/19 - [Programming/Design Pattern ] - Design pattern - Prototype (디자인패턴 - 프로토타입) / Java C++ C#

 

 

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #60 sudoku. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #59 spiralNumbers. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

 

 

2018/12/28 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 - (#9, Tell, Don't Ask)

2018/12/26 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 (1)

 

 

2019/01/14 - [Programming/Java] - 자바 메모리 누수 체크/확인/고치는 방법, Memory leak check/fix in Java application, cleanCode/좋은코드/oop/객체지향

 

 

2019/02/19 - [Life/Health care] - Lysine 라이신 usage/side effects/dosage 효과/효능/부작용/성인,소아 용법, 복용법

2019/02/16 - [Life/Health care] - Finasteride 피나스테라이드,탈모약 usage/side effects/dosage 효능/부작용/효과/sexual effect/두타스테라이드/프로페시아/propecia/finpecia/카피약/copy drug/hair loss

2019/02/25 - [Life/Health care] - Folic Acid 엽산 vitaminB9,비타민M usage/side effects/dosage 효과/효능/부작용/성인,소아 용법, 복용법

2019/02/28 - [Life/Health care] - Vitamin K, 비타민 K usage/side effects/dosage 효능/부작용/성인,소아 용법

2019/03/03 - [Life/Health care] - Vitamin B1, Thiamine, 비타민 B1, 티아민 usage/side effects/dosage 효능/부작용/성인,소아 용법