본문 바로가기

Algorithm/Leet Code

LeetCode #242 ValidAnagram. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

LeetCode #242 ValidAnagram. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접


 금방 풀었고, 한번에 통과했는데 퍼포먼스까지 상위 1% 라서 꿀잠 잘ㄷ스


Solved in a short time at once, also performance is upper 1%. So I could sleep well tonighty night



LeetCode #242

Q.

 Given two strings s and t , write a function to determine if t is an anagram of s.


주어진 두개의 문자열 s 와 t 에서, t 와 s 가 아나그램 인지 확인해봐라 ( 아나그램은 - 알파벳 순서를 바꿔서 같은게 가능한지 )

e.g. iceman -> cinema ( anagram )


e.g. 

Example 1:


Input: s = "anagram", t = "nagaram"

Output: true



Example 2:


Input: s = "rat", t = "car"

Output: false



Process


//Process

//1. Input string s, t

//2. Iterate s from begin to the end

// 2.1. Make s alphabet table

//3. Iterate t from begin to the end

// 3.1. Make t alphabet table

//4. Compare two tables

//5. Return answer



//처리과정

//1. 스트링 s, t 를 입력받는다.

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

// 2.1. s 문자열 알파벳 개수 배열을 만든다.

//3. t 의 시작부터 끝까지 반복한다.

// 3.1. t 문자열 알파벳 개수 배열을 만든다.

//4. 만든 배열들 비교한다.

//5. 결과 반환한다.




Code.. lemme see code!!!

코드.. 코드를 보자!!!




#include <iostream>

#include <string>

#include <vector>


using namespace std;


class Solution {

public:

bool isAnagram(string s, string t) {

bool answer = true;


int alphabetArray1[26] = { 0 };

int alphabetArray2[26] = { 0 };


for (int i = 0; i < s.size(); ++i)

{

++alphabetArray1[s[i] - 97];

}

for (int i = 0; i < t.size(); ++i)

{

++alphabetArray2[t[i] - 97];

}


for (int i = 0; i < (sizeof(alphabetArray1) / sizeof(*alphabetArray1)); ++i)

{

if (alphabetArray1[i] != alphabetArray2[i])

{

return false;

}

}

return answer;

}

};





Something else you might like...?



2019/01/16 - [Algorithm/Leet Code] - LeetCode #217 ContainsDuplicate. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/01/21 - [Algorithm/Leet Code] - LeetCode #219 ContainsDuplicate2. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/01/22 - [Algorithm/Leet Code] - LeetCode #220 ContainsDuplicate3. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/01/23 - [Algorithm/Leet Code] - LeetCode #225 ImplementStackUsingQueue. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접



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

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

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

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

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

2019/01/02 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #52 longestWord. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2019/01/01 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #51 deleteDigit. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/12/31 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #50 chessKnight. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar



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)



2018/12/26 - [Programming/Java] - JavaFx, how to show actual size image bigger than pane using scroll, 실제 크기 이미지를 스크롤바 사용하여 보여주는 방법, Java/cpp/kotlin/gui


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



2018/12/16 - [Life/Health care] - L-Arginine 아르기닌 usage/side effects/dosage 효능/부작용/성인,소아 용법(2)

2018/12/27 - [Life/Health care] - Milk-Thistle 밀크시슬 usage/side effects/dosage/fatigue/supplement,효능/부작용/성인,소아 용법/건강/피로회복/영양제

2018/12/26 - [Life/Health care] - Selenium 셀레늄 usage/side effects/dosage 효능/부작용/성인,소아 용법