본문 바로가기

IT/알고리즘90

18] Leetcode 1475. Final Prices With a Special Discount in a Shop Final Prices With a Special Discount in a Shop - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 숫자 배열을 for문 돌면서 다음 숫자부터 마지막까지 숫자들 중에 for문의 숫자보다 더 작은 게 있는지 확인하는 문제. class Solution { public: vector finalPrices(vector& prices) { vector ans; bool flag = false; for(int i = 0;i 2020. 6. 29.
17] Leetcode 1323. Maximum 69 Number 6과 9로 이뤄진 숫자가 주어졌을 때 단 하나의 6을 9로 바꿨을 때의 최댓값을 리턴하는 문제 Maximum 69 Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 숫자에서 6이 있는 가장 큰 자릿수를 구해서 그 자릿수에 3을 더 해준다 pow함수 사용 class Solution { public: int maximum69Number (int num) { int max6= -1; // 6이 있는 최대 자릿수 int ans = num; for(i.. 2020. 6. 29.
16] Leetcode 1252. Cells with Odd Values in a Matrix Cells with Odd Values in a Matrix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 0으로 채워져 있는 배열의 숫자들을 indices 배열대로 증가시키고 홀수의 개수를 반환하는 문제다. 예시를 설명하면 n = 2, m = 3으로 2행 3열의 배열 있고 indices = [[0,1], [1,1]]으로, 첫 번째는 0행과 1열의 모든 숫자 1씩 증가시키고 두 번째는 1행과 1열의 모든 숫자를 증가시켜 [1,3,1], [1,3,1]이 된다... 2020. 6. 27.
15] Leetcode 1464. Maximum Product of Two Elements in an Array Maximum Product of Two Elements in an Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 최댓값과 그다음 최댓값을 구하는 문제다. class Solution { public: int maxProduct(vector& nums) { int max1=0; int location1=0; int max2=0; int location2=0; for(int i = 0; i max1){ max1 = nums[i]; location1 =.. 2020. 6. 25.