<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>qorthal_.log</title>
        <link>https://velog.io/</link>
        <description>넌 할 수 있어 라고 말해 주세요~</description>
        <lastBuildDate>Tue, 26 Mar 2024 14:33:48 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <copyright>Copyright (C) 2019. qorthal_.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/qorthal_" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[JAVA] 프로그래머스-두 정수 사이의 합 12912]]></title>
            <link>https://velog.io/@qorthal_/JAVA-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%91%90-%EC%A0%95%EC%88%98-%EC%82%AC%EC%9D%B4%EC%9D%98-%ED%95%A9-12912</link>
            <guid>https://velog.io/@qorthal_/JAVA-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%91%90-%EC%A0%95%EC%88%98-%EC%82%AC%EC%9D%B4%EC%9D%98-%ED%95%A9-12912</guid>
            <pubDate>Tue, 26 Mar 2024 14:33:48 GMT</pubDate>
            <description><![CDATA[<h3 id="--문제를-보자마자">- 문제를 보자마자</h3>
<p>&#39;정수&#39;를 &#39;소수&#39;로 착각한 나자신.
쉬운 문제를 어렵게 꼬아서 풀려했던 나자신.</p>
<p>1과 자기자신만 약수로 가지는 소수로 착각해서 이걸 재귀함수를 써야하나... 루트를 써야하나... 생각이 많았다.</p>
<blockquote>
<p>하지만 정수는?
자연수(양의 정수)와 0과 자연수에 -를 붙인 음의 정수를 포함한 모든 값을 말한다.</p>
</blockquote>
<p>따라서, 그저 주어진 a와 b 범위 사이의 정수값을 더하면 되는 문제이다.</p>
<p>그런데, a와 b도 오름차순으로 주어진 게 아니다. 그래서 둘 중에 누가 큰지를 따져야한다.</p>
<h4 id="--처음-코드는">- 처음 코드는</h4>
<pre><code>class Solution {
    public long solution(int a, int b) {
        long answer = 0;

        if(a==b){
            return a;    
        }

        int min = Math.min(a,b);
        int max = Math.max(a,b);

        for(; min&lt;=max; min++){
            answer += min;
        }
        return answer;
    }
}</code></pre><p>if문으로 a와 b가 같은 지 우선 확인 후 같다면 a 반환,
아니라면 최대최소를 따져 for문을 돌리도록 짰다.</p>
<p><strong>하지만 생각해보니 최대최소를 따지고 for문을 돌린다면, 같은 값일 때는 어차피 answer에 하나의 값만 더해지기 때문에 굳이 if가 있을 필요가 없었다.</strong></p>
<h4 id="--수정한-코드">- 수정한 코드</h4>
<pre><code>class Solution {
    public long solution(int a, int b) {
        long answer = 0;

        int min = Math.min(a,b);
        int max = Math.max(a,b);

        for(; min&lt;=max; min++){
            answer += min;
        }
        return answer;
    }
}</code></pre><p>한결 짧아졌다.</p>
<h4 id="--다른-사람의-풀이-참고">- 다른 사람의 풀이 참고</h4>
<pre><code>class Solution {

    public long solution(int a, int b) {
        return sumAtoB(Math.min(a, b), Math.max(b, a));
    }

    private long sumAtoB(long a, long b) {
        return (b - a + 1) * (a + b) / 2;
    }
}</code></pre><p>등차수열의 합 공식을 이용한 방식</p>
<pre><code>class Solution {
  public long solution(int a, int b) {
      long answer = 0;
      for (int i = ((a &lt; b) ? a : b); i &lt;= ((a &lt; b) ? b : a); i++) 
          answer += i;

      return answer;
  }
}</code></pre><p>for문 안에 삼항을 쓰는 방식</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[IntelliJ IDEA Ultimate 설치 방법]]></title>
            <link>https://velog.io/@qorthal_/IntelliJ-IDEA-Ultimate-%EC%84%A4%EC%B9%98-%EB%B0%A9%EB%B2%95</link>
            <guid>https://velog.io/@qorthal_/IntelliJ-IDEA-Ultimate-%EC%84%A4%EC%B9%98-%EB%B0%A9%EB%B2%95</guid>
            <pubDate>Thu, 07 Sep 2023 03:16:17 GMT</pubDate>
            <description><![CDATA[<p>필자 .exe 파일로 다운</p>
<p><img src="https://velog.velcdn.com/images/qorthal_/post/ed4248fd-6f0b-487d-9226-c4414eb2246d/image.png" alt=""></p>
<ul>
<li>next 버튼</li>
</ul>
<p><img src="https://velog.velcdn.com/images/qorthal_/post/e178a49e-e185-4bef-80de-4e5956ed8df3/image.png" alt=""></p>
<ul>
<li>설치 경로 선택</li>
</ul>
<p><img src="https://velog.velcdn.com/images/qorthal_/post/4ed802b2-0892-416a-a936-2b422e4360e9/image.png" alt=""></p>
<ul>
<li>인텔리제이 설치 옵션 선택 후 next 버튼</li>
</ul>
<p>[옵션 정리]</p>
<ul>
<li>Create Desktop Shortcut : 바탕화면 바로가기 생성 여부</li>
<li>Update Path Variable : 윈도우 환경 변수에 자동으로 추가</li>
<li>Update Context Menu : 프로젝트로 폴더 열기</li>
<li>Create Association : 사용할 환경 선택 옵션</li>
</ul>
<p><img src="https://velog.velcdn.com/images/qorthal_/post/6f27a939-1180-4139-9309-1b3f9f23c7f7/image.png" alt="">
Install 클릭</p>
<h3 id="설치-후">설치 후</h3>
<p><img src="https://velog.velcdn.com/images/qorthal_/post/00288a79-02f6-42f7-9e37-b513a3616e40/image.png" alt=""></p>
<ul>
<li>체크 후 Continue</li>
</ul>
<h4 id="라이센스-등록">라이센스 등록</h4>
<p><img src="https://velog.velcdn.com/images/qorthal_/post/5e4caa9d-2290-482c-a441-da7253ef4ffa/image.png" alt=""></p>
<ul>
<li>디폴트 체크 상태에서 JetBrains 계정 로그인만 해주었슴다
<img src="https://velog.velcdn.com/images/qorthal_/post/9332acd8-5027-4e54-adec-7df0e105e8f5/image.png" alt="">
이렇게 인증을 마치면
<img src="https://velog.velcdn.com/images/qorthal_/post/ae87385d-071e-4cdb-9596-37b6b8aab75c/image.png" alt="">
Activate 버튼이 뜹니다
<img src="https://velog.velcdn.com/images/qorthal_/post/21b0f447-54a6-400e-893d-6c80e7d6b874/image.png" alt="">
Continue 눌러주면 끝</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[SOLID란]]></title>
            <link>https://velog.io/@qorthal_/SOLID%EB%9E%80</link>
            <guid>https://velog.io/@qorthal_/SOLID%EB%9E%80</guid>
            <pubDate>Tue, 22 Aug 2023 05:44:36 GMT</pubDate>
            <description><![CDATA[<h1 id="solid">SOLID</h1>
<p>클린코드로 유명한 로버트 마틴이 정리한 좋은 객체 지향 설계의 5가지 원칙</p>
<ul>
<li>SRP : 단일 책임 원칙(single responsibility principle)</li>
<li>OCP : 개방-폐쇄 원칙(Open/closed principle)</li>
<li>LSP : 리스코프 치환 원칙(Liskov substitution principle)</li>
<li>ISP : 인터페이스 분리 원칙(Interface segregation principle)</li>
<li>DIP : 의존관계 역전 원칙(Dependency inversion principle)</li>
</ul>
<br>
<br>


<h3 id="srp-단일-책임-원칙">SRP 단일 책임 원칙</h3>
<h4 id="single-responsibility-principle">Single responsibility principle</h4>
<ul>
<li>한 클래스는 하나의 책임만 가져야 한다.</li>
<li>하나의 책임은 모호하다. (클 수도, 작을 수도 / 문맥과 상황에 따라 다름)</li>
<li><strong>변경이 중요한 기준</strong>이 된다. 변경이 있을 때 파급 효과가 적으면 단일 책임 원칙을 잘 따른 것</li>
<li>예) UI 변경, 객체의 생성과 사용을 분리</li>
</ul>
<br>
<br>

<h3 id="ocp-개방-폐쇄-원칙">OCP 개방-폐쇄 원칙</h3>
<h4 id="openclosed-principle">Open/closed principle</h4>
<ul>
<li>소프트웨어 요소는 <strong>확장에는 열려 있으나 변경에는 닫혀 있음</strong></li>
<li>다형성 활용</li>
<li>인터페이스를 구현한 새로운 클래스를 하나 만들어서 새로운 기능을 구현</li>
</ul>
<br>
<br>

<h3 id="lsp-리스코프-치환-원칙">LSP 리스코프 치환 원칙</h3>
<h4 id="liskov-subsititution-principle">Liskov subsititution principle</h4>
<ul>
<li>프로그램의 객체는 프로그램의 정확성을 깨뜨리지 않으면서 하위 타입의 인스턴스로 바꿀 수 있어야함</li>
<li>다형성에서 하위 클래스는 인터페이스 규약을 다 지켜야함</li>
<li>다형성을 지원하기 위한 원칙</li>
<li>단순히 컴파일에 성공하는 것을 넘어서는 이야기</li>
<li>예) 자동차 인터페이스의 악셀은 앞으로 가라는 기능인데, 뒤로 가도록 구현하면 컴파일은 되겠지만 기능을 위반한 LSP 위반이 된다. 속도가 달라지더라도 앞으로 가는 기능은 구현되어야 함</li>
</ul>
<p><br><br></p>
<h3 id="isp-인터페이스-분리-원칙">ISP 인터페이스 분리 원칙</h3>
<h4 id="interface-segregation-principle">Interface segregation principle</h4>
<ul>
<li>특정 클라이언트를 위한 인터페이스 여러 개가 범용 인터페이스 하나보다 낫다.</li>
<li>자동차 인터페이스 -&gt; 운전 인터페이스, 정비 인터페이스로 분리</li>
<li>사용자 인터페이스 -&gt; 운전자 클라이언트, 정비사 클라이언트로 분리</li>
<li>분리하면 운전 인터페이스 자체가 변해도 정비사 클라이언트에는 영향이 없음</li>
<li>인터페이스가 명확해지고, 대체 가능성이 높아짐</li>
</ul>
<p><br><br></p>
<h3 id="dip-의존관계-역전-원칙">DIP 의존관계 역전 원칙</h3>
<h4 id="dependency-inversion-principle">Dependency inversion principle</h4>
<ul>
<li>구체화에 의존하지 않고, 추상화에 의존하는 것</li>
<li>즉, 구현 클래스에 의존하지 말고, 인터페이스에 의존</li>
<li>구현체에 의존하게 되면 변경이 어려워짐. 클라이언트가 인터페이스에 의존해야 유연한 구현체 변경이 가능함</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Java] 이진수 정렬]]></title>
            <link>https://velog.io/@qorthal_/Java-%EC%9D%B4%EC%A7%84%EC%88%98-%EC%A0%95%EB%A0%AC</link>
            <guid>https://velog.io/@qorthal_/Java-%EC%9D%B4%EC%A7%84%EC%88%98-%EC%A0%95%EB%A0%AC</guid>
            <pubDate>Fri, 11 Aug 2023 12:13:08 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p>매개변수 nums에 숫자가 주어지면 nums의 원소들을 이진수로 변환했을 때 1의 개수가 적은
것부터 많은 것 순으로 정렬하여 반환하는 프로그램을 작성하세요.
만약 nums = [5, 6, 7, 8, 9]이고 이 원소들을 이진수로 변환하면
5 --&gt; 101 : 1이 2개
6 --&gt; 110 : 1이 2개
7 --&gt; 111 : 1이 3개
8 --&gt; 1000 : 1이 1개
9 --&gt; 1001 : 1이 2개
이고, 이 수들을 이진수에서 1의 개수에 의해 오름차순 정렬하면 [8, 5, 6, 9, 7]이다.
위에 5, 6, 9는 이진수로 변환했을 때 1의 개수가 2개로 동일하면 십진수가 작은순(오름차순)으로 정렬합니다.</p>
<p><strong>입출력 예</strong>
| nums | answer |
| ---- | ------ |
| [5, 6, 7, 8, 9] | [8, 5, 6, 9, 7] |
| [5, 4, 3, 2, 1] | [1, 2, 4, 3, 5] |
| [12, 5, 7, 23, 45, 21, 17] | [5, 12, 17, 7, 21, 23, 45] |</p>
<p>제한사항:
• nums의 길이는 1,000을 넘지 않습니다.
• 1 &lt;= nums[i] &lt;= 100,000</p>
<h3 id="풀이">풀이</h3>
<p>2차원 배열을 생성해서 arr[i][[0] 자리에는 숫자를 arr[i][1] 자리에는 숫자를 이진수로 바꿨을 때 1의 개수를 넣는다.
그 후 arr[i][1]을 기준으로 정렬한다.</p>
<h3 id="코드">코드</h3>
<pre><code>import java.util.*;
class Solution {
    public int[] solution(int[] nums){
        int[] answer = new int[nums.length];
        int[][] tmp = new int[nums.length][2];

        for(int i=0; i&lt;nums.length; i++){
            int cnt = 0;
            int num = nums[i];
            while(num &gt; 0){
                if(num%2 == 1){
                    cnt++;
                }
                num /= 2;
            }
            tmp[i][0] = nums[i];
            tmp[i][1] = cnt;
        }
        Arrays.sort(tmp, (a,b)-&gt;a[1]==b[1]?a[0]-b[0]:a[1]-b[1]);
        for(int i=0; i&lt;answer.length; i++){
            answer[i] = tmp[i][0];
        }
        return answer;
    }

    public static void main(String[] args){
        Solution T = new Solution();
        System.out.println(Arrays.toString(T.solution(new int[]{5, 6, 7, 8, 9})));
        System.out.println(Arrays.toString(T.solution(new int[]{5, 4, 3, 2, 1})));
        System.out.println(Arrays.toString(T.solution(new int[]{12, 5, 7, 23, 45, 21, 17})));
    }
}</code></pre><br>

<h3 id="기타">기타</h3>
<p>이진수로 바꿔서 1을 셀 때, if로 판별하고 cnt를 넣는 것 뿐만 아닌 num%2한 값을 더해줄 수도 있음</p>
<pre><code>while(tmp &gt; 0){
     cnt += (tmp % 2);
     tmp = tmp / 2;
}</code></pre><p>이런식으로</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Java] LeetCode 977. Squares of a Sorted Array]]></title>
            <link>https://velog.io/@qorthal_/Java-LeetCode-977.-Squares-of-a-Sorted-Array</link>
            <guid>https://velog.io/@qorthal_/Java-LeetCode-977.-Squares-of-a-Sorted-Array</guid>
            <pubDate>Tue, 01 Aug 2023 14:43:38 GMT</pubDate>
            <description><![CDATA[<p><a href="https://leetcode.com/problems/squares-of-a-sorted-array/">https://leetcode.com/problems/squares-of-a-sorted-array/</a></p>
<h3 id="문제">문제</h3>
<p>Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
배열값을 제곱한 수를 오름차순 정렬</p>
<h3 id="소스코드">소스코드</h3>
<pre><code>class Solution {
    public int[] sortedSquares(int[] nums) {
        int[] arr = new int[nums.length];
        for(int i=0; i&lt;nums.length; i++){
            arr[i] = nums[i] * nums[i];
        }
        Arrays.sort(arr);
        return arr;
    }
}</code></pre><h3 id="설명">설명</h3>
<p>새로운 배열 arr 정의해서 제곱값을 넣음
Arrays.sort() 함수를 사용하여 arr 정렬</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Java] LeetCode 1295. Find Numbers with Even Number of Digits]]></title>
            <link>https://velog.io/@qorthal_/Java-LeetCode-1295.-Find-Numbers-with-Even-Number-of-Digits</link>
            <guid>https://velog.io/@qorthal_/Java-LeetCode-1295.-Find-Numbers-with-Even-Number-of-Digits</guid>
            <pubDate>Tue, 01 Aug 2023 14:40:41 GMT</pubDate>
            <description><![CDATA[<p><a href="https://leetcode.com/problems/find-numbers-with-even-number-of-digits/">https://leetcode.com/problems/find-numbers-with-even-number-of-digits/</a></p>
<h3 id="문제">문제</h3>
<p>Given an array nums of integers, return how many of them contain an even number of digits.
자리수가 짝수인 수의 개수</p>
<h3 id="소스코드">소스코드</h3>
<pre><code>class Solution {
    public int findNumbers(int[] nums) {
        int k = 0;
        int ans = 0;
        for(int i : nums){
            while(i!=0){
                i /= 10;
                k++;
            }
            if(k%2 == 0){
                ans++;
            }
            k = 0;
        }
        return ans;
    }
}</code></pre><h3 id="설명">설명</h3>
<p>10으로 계속 나누고 k에 자리수 저장
k가 짝수일때 ans에 +1</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Java] LeetCode 485. Max Consecutive Ones]]></title>
            <link>https://velog.io/@qorthal_/Java-LeetCode-485.-Max-Consecutive-Ones</link>
            <guid>https://velog.io/@qorthal_/Java-LeetCode-485.-Max-Consecutive-Ones</guid>
            <pubDate>Tue, 01 Aug 2023 14:36:05 GMT</pubDate>
            <description><![CDATA[<p><a href="https://leetcode.com/problems/max-consecutive-ones/">https://leetcode.com/problems/max-consecutive-ones/</a></p>
<h3 id="문제">문제</h3>
<p>Given a binary array nums, return the maximum number of consecutive 1&#39;s in the array.
연속된 1의 최대 개수를 리턴</p>
<h3 id="소스코드">소스코드</h3>
<pre><code>class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
        int cnt = 0;
        int max = 0;

        for(int i : nums){
            if(i == 1){
                cnt++;
                if(cnt &gt; max){
                    max = cnt;
                }
            } else {
                cnt = 0;
            }
        }
        return max;
    }
}</code></pre><h3 id="설명">설명</h3>
<p>1이 나오면 cnt의 개수를 올리고, 0이 나오면 cnt를 0으로 초기화
max에 cnt의 최대값을 넣고 리턴</p>
]]></description>
        </item>
    </channel>
</rss>