본문 바로가기

Algorithm

(2139)
(C++) - LeetCode (easy) 819. Most Common Word https://leetcode.com/problems/shortest-distance-to-a-character/description/ Shortest Distance to a Character - LeetCode Can you solve this real interview question? Shortest Distance to a Character - Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest leetcode.com 구현 문제였습니..
(C++) - LeetCode (easy) 819. Most Common Word https://leetcode.com/problems/most-common-word/description/ Most Common Word - LeetCode Can you solve this real interview question? Most Common Word - Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and tha leetcode.com 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 단어와 빈도수를 저장..
(C++) - LeetCode (easy) 812. Largest Triangle Area https://leetcode.com/problems/largest-triangle-area/description/ 📕 풀이방법 📔 입력 및 초기화 정답변수 maxArea 를 선언 후 0으로 초기화해줍니다. 📔 풀이과정 점 3개의 좌표를 알고 있다면 사선공식을 사용해 삼각형 면적을 구할 수 있으므로 3차원 for loop를 수행하며 최대 삼각형 면적을 구해 maxArea 📔 정답 출력 | 반환 maxArea를 반환합니다. 📕 Code 📔 C++ struct Point { int x,y; }; class Solution { public: double getTriangleArea(Point a, Point b, Point c){ return abs((a.x*b.y + b.x*c.y + c.x*a.y) - (..
(C++) - LeetCode (easy) 806. Number of Lines To Write String https://leetcode.com/problems/number-of-lines-to-write-string/description/ Number of Lines To Write String - LeetCode Can you solve this real interview question? Number of Lines To Write String - You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of leetcode.com 구현 문제였습니다. ..
(C++) - LeetCode (easy) 804. Unique Morse Code Words https://leetcode.com/problems/unique-morse-code-words/description/
(C++) - LeetCode (easy) 796. Rotate String https://leetcode.com/problems/rotate-string/description/ Rotate String - LeetCode Can you solve this real interview question? Rotate String - Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position. leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 풀이과정 1. 왼쪽으로 x칸만큼 움직인 문자열..
(C++) - LeetCode (easy) 771. Jewels and Stones https://leetcode.com/problems/jewels-and-stones/ Jewels and Stones - LeetCode Can you solve this real interview question? Jewels and Stones - You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to kno leetcode.com 자료구조를 이용한 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 보석의 종류를 O..
(C++) - LeetCode (easy) 766. Toeplitz Matrix https://leetcode.com/problems/toeplitz-matrix/description/ Toeplitz Matrix - LeetCode Can you solve this real interview question? Toeplitz Matrix - Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements. Example 1: leetcode.com 구현 문제였습니다. 📕 풀이방법 📔 풀이과정 1. 화살표 방향으로 한 번씩 검사해서 ..