알고리즘 47

LeetCode1717. Maximum Score From Removing Substrings

https://leetcode.com/problems/maximum-score-from-removing-substrings/submissions/1321816444/?envType=daily-question&envId=2024-07-12       1. 문제 및 접근   1717. Maximum Score From Removing Substrings String 값을 주고, ab를 지우면 x점수, ba를 지우면 y점수를 얻을 수 있다최대 얻을 수 있는 점수를 반환 높은 점수대로 그리디를 쓰면 될 것 같은데 전체 탐색하니 시간초과StringBulider에 담아서 담을 때 마다 판별 후 삭제하자   Constraints:1 1 s consists of lowercase English letters.     ..

알고리즘 2024.07.16

99클럽 코테 스터디 40일차 TIL Optimal Partition of String

https://leetcode.com/problems/optimal-partition-of-string/description/ 비트연산자map     1. 문제 및 접근   2405. Optimal Partition of String 주어진 s의 서브 스트링을 구성하는데, 중복된 char가 없게 만들어야 한다최소의 subString 갯수를 반환"abacaba" 라면 "ab" "ac" ,"aba"로 나눴다면  aba에서 a가 2개라 안됨s = abacaba 라면 앞에서부터 시작해서 있는 수 중 같은 수가 들어오면 그전까지 담기 ?각 substring은 중복되도 되는 듯 하다   Constraints:1 s consists of only English lowercase letters.       2. 풀이 ..

알고리즘 2024.06.28

99클럽 코테 스터디 39일차 TIL Reduce Array Size to The Half

https://leetcode.com/problems/reduce-array-size-to-the-half/    그리디map.merge      1. 문제 및 접근  1338. Reduce Array Size to The Half 배열이 주어지면 배열 안에 있는 수 중 하나를 골라 그 수를 다 없앨 수 있다.그럴 때 반 이상 줄일 수 있는 최소의 수의 최소 갯수 반환 arr = [3,3,3,3,5,5,5,2,2,7]map으로 찾고, 그 수를 돌면서 반 이상되면 바로 리턴 ? 3 =4 5=3 2=2 7=1키 값은 상관 없음 번호로 부여하고, 몇개인지가 중요   Constraints:2 arr.length is even.1      2.  풀이 public int minSetSize(int[] arr) {..

알고리즘 2024.06.27

99클럽 코테 스터디 38일차 TIL Seat Reservation Manager feat.Heap

https://leetcode.com/problems/seat-reservation-manager/   heap    1.  문제 및 접근    1845. Seat Reservation Manager 3개의 메서드1. SeatManager(int n)의 자리 초기화2. reserve 예약하면 작은 수부터 예약하고, 작은 수 반환3. unreserve 들어온 자석 번호 취소 void O(n)으로 푸니 마지막에 시간초과 걸림  Constraints:1 1 For each call to reserve, it is guaranteed that there will be at least one unreserved seat.For each call to unreserve, it is guaranteed that se..

알고리즘 2024.06.26

99클럽 코테 스터디 36일차 TIL Removing Stars From a String

https://leetcode.com/problems/removing-stars-from-a-string/submissions/1298687817/   1. 문제 및 접근    2390. Removing Stars From a StringString이 주어지면 그 안에 있는 *가 들어온 만큼 왼쪽 char를 지우기순서가 중요하다 * 나오면 바로 왼쪽 꺼 지워주기전부 다 유효하다. Input: s = "leet**cod*e"Output: "lecoe" 왼쪽이니까 stack에 넣으면서 *이 나오면 다음 인덱스로 가면 될 듯   Note:The input will be generated such that the operation is always possible.It can be shown that the r..

알고리즘 2024.06.24

99클럽 코테 스터디 35일차 TIL Flatten Nested List Iterator

https://leetcode.com/problems/flatten-nested-list-iterator/description/   queuestackimp    1. 문제 및 접근   감싸있는 거 다 빼고 정수만 반환하라 3가지 메서드1. list형태의 nestedList가 들어오면 초기화2. next의 경우 들어오면, 다음 정수 반환3. hasNext 다음 수가 있음 true 아님 false [[1,1],2,[1,1]] = [1,1,2,1,1]  판단 방식은 while문에서 hasNext가 true면 next를 호출  stack or queue ? ide 예제로 확인하기 위해NestedInteger인터페이스 및 클래스 구현까지  Constraints: 1 The values of the integer..

알고리즘 2024.06.24