본문 바로가기

Algorithm/Leet Code

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

LeetCode #844 BackspaceStringCompare. 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 Backspace String Compare.

 

Memory Usage: 8.4 MB, less than 81.82% of C++ online submissions for Backspace String Compare.

 

 

 

LeetCode #844

Q.

Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.

 

 주어진 문자열 S, T 가 있는데, 빈 텍스트 에디터에 입력되었을 때 같은 문자인지 확인해서 리턴해라. # 은 백스페이스를 의미하는 문자이다.

 

 

 

Example 1:

 

Input: S = "ab#c", T = "ad#c"

Output: true

 

Explanation: Both S and T become "ac".

 

 

Example 2:

 

Input: S = "ab##", T = "c#d#"

Output: true

 

Explanation: Both S and T become "".

 

 

 

Example 3:

 

Input: S = "a##c", T = "#a#c"

Output: true

 

Explanation: Both S and T become "c".

 

 

 

Example 4:

 

Input: S = "a#c", T = "b"

Output: false

 

Explanation: S becomes "c" while T becomes "b".

 

 

 

Note:

  1. 1 <= S.length <= 200
  2. 1 <= T.length <= 200
  3. S and T only contain lowercase letters and '#' characters.

 

 

Process

// Process
//1. Input two strings S, T
//2. Iterate from begin to the end
// 2.1. Check if it's # or not
//  2.1.1. If so -> delete front char
// 2.2. Delete # char
//3. Return result after checking they are same or not

 

 

// 처리과정

//1. 문자열 S, T 입력받는다.

//2. 시작부터 끝까지 반복한다.

// 2.1. 해당 문자가 # 인지 확인해서

//  2.1.1. # 이면 -> 앞의 글자를 지운다

// 2.2. # 글자 지운다

//3. 같은지 확인해서 결과 반환한다.

 

 

 

Code.. lemme see example code!!!

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

 

 

 

class Solution {
public:
	bool backspaceCompare(string S, string T) {
		bool result = false;
		
		for (int i = 0; i < S.length(); ++i) {
            if (S[i] == '#') {
                if (i > 0) {
                    S.erase(S.begin() + (i-1));
                    --i;
                }
                S.erase(S.begin() + i);
                --i;
            }
        }
		for (int i = 0; i < T.length(); ++i) {
            if (T[i] == '#') {
                if (i > 0) {
                    T.erase(T.begin() + (i-1));
                    --i;
                }
                T.erase(T.begin() + i);
                --i;
            }
        }

		if (S == T) {
			result = true;
		}

		return result;
	}
};

 

 

 

Something else you might like...?

 

 

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/10/20 - [Algorithm/Leet Code] - LeetCode #181 EmployeesEarningMoreTheirManagers. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면..

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

2019/10/14 - [Algorithm/Leet Code] - LeetCode #182 DuplicateEmails. 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

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

2019/01/07 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #57 fileNaming. 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 효능/부작용/성인,소아 용법