본문 바로가기

Algorithm/LeetCode4

[LeetCode] 1544. Make The String Great (java) ✏️ 문제 Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: 0 2024. 4. 6.
[LeetCode] 1913. Maximum Product Difference Between Two Pairs (java) ✏️ 문제 The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d). For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16. Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized. Return the maximum such product dif.. 2023. 12. 19.
[LeetCode] #1887. Reduction Operations to Make the Array Elements Equal ✏️ 문제 Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps: Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.Reduce .. 2023. 11. 19.
[LeetCode] 876. Middle of the Linked List (java) ✏️ 문제 Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. 🤖 알고리즘 #링크드리스트 #투포인터 🤯 풀이 방법 주어진 리스트의 전체 길이를 구하고 절반까지 도달할 때까지 next로 이동하는 방식으로 풀었다. 메모리 효율이 좋지 않아서 확인해보니 투포인터를 이용해서 복사해서 길이를 구할 필요 없이 인덱스만 이용해서 한 바퀴만 돌게 푸는 게 더 효율적인 방법인 듯! 👾 구현 코드 (자바) class Solution { public ListNode middleNode(ListNode head) { in.. 2023. 10. 30.
728x90