본문 바로가기

Algorithm/Brute Force

(118)
(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) 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) 653. Two Sum IV - Input is a BST https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/ Two Sum IV - Input is a BST - LeetCode Can you solve this real interview question? Two Sum IV - Input is a BST - Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise. Example 1: [http leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 입..
(C++) - LeetCode (easy) 599. Minimum Index Sum of Two Lists https://leetcode.com/problems/minimum-index-sum-of-two-lists/description/ Minimum Index Sum of Two Lists - LeetCode Can you solve this real interview question? Minimum Index Sum of Two Lists - Given two arrays of strings list1 and list2, find the common strings with the least index sum. A common string is a string that appeared in both list1 and list2. A common string w leetcode.com 전수조사로 푼 문제였습..
(C++) - LeetCode (easy) 520. Detect Capital https://leetcode.com/problems/detect-capital/ Detect Capital - LeetCode Can you solve this real interview question? Detect Capital - We define the usage of capitals in a word to be right when one of the following cases holds: * All letters in this word are capitals, like "USA". * All letters in this word are not capitals, like leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 풀이과정 모두 대문자거나, 모두 소문자거나, 처음만 대문자인 ..
(C++) - LeetCode (easy) 507. Perfect Number https://leetcode.com/problems/perfect-number/description/ Perfect Number - LeetCode Can you solve this real interview question? Perfect Number - A perfect number [https://en.wikipedia.org/wiki/Perfect_number] is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 제한이 1천만이므로 O(n..
(C++) - LeetCode (easy) 500. Keyboard Row https://leetcode.com/problems/keyboard-row/description/ Keyboard Row - LeetCode Can you solve this real interview question? Keyboard Row - Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below. In the American keyboard: * the first ro leetcode.com 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. 첫 째, 둘 째, 셋 째 ..