본문 바로가기

전체 글310

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.
14] Leetcode 1221. Split a String in Balanced Strings Split a String in Balanced Strings - 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 R과 L로 구성된 문자열을 R과 L의 개수가 똑같은 문자열로 나누려고 한다. 가장 많이 쪼갰을 때 그 숫자를 리턴하는 문제. 살짝 헷갈릴 수도 있지만 그냥 앞에서부터 R, L 개수를 각각 세면서 둘이 같아질 때를 리턴하면 된다. class Solution { public: int balancedStringSplit(string s) { int ans=.. 2020. 6. 25.
13] Leetcode 709. To Lower Case To Lower Case - 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: string toLowerCase(string str) { for(int i=0;i='A' && str[i] 2020. 6. 25.
12] Leetcode 1486. XOR Operation in an Array 배타적 논리합, XOR 연산에 관한 문제다. XOR Operation 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 초기값만 start로 해주고 나머지는 이어서 고대로 해주면 된다. class Solution { public: int xorOperation(int n, int start) { int ans = start; for(int i = 1;i 2020. 6. 24.