no image
[flutter/플러터] Row, Column
요소 가로 배치 : Row() 세로 배치 : Column()
2022.05.23
htaccess 파일 수정하여 http를 https로 리다이렉트 + php hsts 설정
.htaccess 파일에 아래 코드 삽입 RewriteEngine On RewriteBase / # HTTP로 접속 된 경우, RewriteCond %{HTTPS} off # 아래의 URL은 항상 https로 리다이렉트 RewriteCond %{HTTP_HOST} www.example.com RewriteCond %{REQUEST_URI} ^/admin/.*$ [OR] RewriteCond %{REQUEST_URI} ^/inquiry/.*$ # 단 아래를 제외하고. RewriteCond %{REQUEST_URI} !^/assets/.*$ RewriteCond %{REQUEST_URI} !^.*\.(js|css|gif|jpg|png|ico|php)$ # https로 리다이렉트 RewriteRule ^.*$..
2022.05.11
[kotlin] leetcode - 283. Move Zeroes
283. Move Zeroes : https://leetcode.com/problems/move-zeroes/ Move Zeroes - 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 { fun moveZeroes(nums: IntArray): Unit { val arr = arrayListOf(); val numList = arrayListOf(); nums.forEach{ when(it) { 0 -> arr.add(it) else -..
2022.05.02
[kotlin] leetcode - Squares of a Sorted Array
977. Squares of a Sorted Array : https://leetcode.com/problems/squares-of-a-sorted-array/ Squares of a Sorted 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 { fun sortedSquares(nums: IntArray): IntArray { for(i in 0 until nums.size){ nums[i] *= nums[i]; } va..
2022.04.27
[kotlin] leetcode - Search Insert Position
35. Search Insert Position : https://leetcode.com/problems/search-insert-position/ Search Insert Position - 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 { fun searchInsert(nums: IntArray, target: Int): Int { var low = 0; var high = nums.lastIndex; while(lo..
2022.04.27
[kotlin] leetcode - Binary Search
704. Binary Search : https://leetcode.com/problems/binary-search/submissions/ Binary Search - 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 { fun search(nums: IntArray, target: Int): Int { //nums에 특정 값 있는 지 확인 var check = nums.contains(target) if(check == true){ va..
2022.04.26
[python/연결리스트] leetcode - Add Two Numbers 문제
leetcode 문제 : https://leetcode.com/problems/add-two-numbers/ # Definition for singly-linked list. # class ListNode(object): # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ num1,num2,total = 0,0,0 i,j = 0,0 while(l1): num1 += l1.val *(10 ** i) i += 1 ..
2022.04.20
[python/Array] leetcode - two sum 문제
쉬운거 부터.. 쉬워도 다시한번 돌아보고 풀자ㅎㅎ 문제 : Two Sum - https://leetcode.com/problems/two-sum/ class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): a = nums[i] for j in range(1, len(nums)): b = nums[j] if i == j: continue if a + b == target: return [i,j] 57 / 57 test cases passed. Status: Accepted Runtime: 8323 ms Memory Usage: 14.9 MB Hash map을 활용하여 푸는 문제. ..
2022.04.18

[flutter/플러터] Row, Column

얘리밍
|2022. 5. 23. 14:03
320x100
728x90

 

 

요소 가로 배치 : Row()

 

 

       세로 배치 : Column()

728x90
반응형
320x100
728x90

 

 

.htaccess 파일에 아래 코드 삽입 

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /

  # HTTP로 접속 된 경우,
  RewriteCond %{HTTPS} off
  # 아래의 URL은 항상 https로 리다이렉트
  RewriteCond %{HTTP_HOST} www.example.com
  RewriteCond %{REQUEST_URI} ^/admin/.*$ [OR]
  RewriteCond %{REQUEST_URI} ^/inquiry/.*$ 

  # 단 아래를 제외하고.
  RewriteCond %{REQUEST_URI} !^/assets/.*$
  RewriteCond %{REQUEST_URI} !^.*\.(js|css|gif|jpg|png|ico|php)$
  
  # https로 리다이렉트
  RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


  # HTTPS로 접속 된 경우,
  RewriteCond %{HTTPS} on
  # 아래의 URL이외는 항상 http로 리다이렉트
  RewriteCond %{HTTP_HOST} www.example.com
  RewriteCond %{REQUEST_URI} !^/admin/.*$
  RewriteCond %{REQUEST_URI} !^/inquiry/.*$
  
  # 단 아래를 제외하고.
  RewriteCond %{REQUEST_URI} !^/assets/.*$
  RewriteCond %{REQUEST_URI} !^.*\.(js|css|gif|jpg|png|ico|php)$
  
  # http로 리다이렉트
  RewriteRule ^.*$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

</IfModule>

 


 

1) 모든 트래픽에 대해 https 강제 적용하기

 

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 

 

2) 특정 도메인에만 https 강제 적용하기

 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain1.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

(빨간 부분에 https 적용을 제외하고 싶은 도메인 주소 작성)

 

 

3) 특정 폴더만 https 적용하기

 

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 
 

<php hsts 적용하기>

 

header.php 에 아래 코드 적용

enableHSTS.php

<?php header("strict-transport-security: max-age=31536000; includeSubDomains; preload"); >

 

disable 시키고 싶을 때, 

disableHSTS.php

<?php header("strict-transport-security: max-age=0;preload"); >

 

* HSTS 옵션

 

1) max-age : hsts 정책을 적용할 기간(초)를 설정

2) includeSubdomains : 도메인(example.com)의 서브 도메인 (*.example.com 등)에도 hsts 설정을 적용

3) preload : 해당 도메인을 hsts 적용 preload list에 추가하도록 함

 

 

 

(참고)

 

preload list

  • HSTS는 HTTPS로 웹 사이트에 접속하기 위해 적어도 한번 웹 서버와 통신을 해야하는데 통신 전에 미리 HTTPS로 접속하도록 목록을 미리 만들어 놓은 것.
  • 브라우저에서 지원하는 기능이며, 브라우저 안에 기본적으로 내장되어 있는 사이트 목록들이 있음
  • 서버가 헤더에 preload값을 내려주면 이 목록에 해당 사이트도 추가 됨.
  • preload에 추가된 사이트는 서버가 HSTS 헤더를 삭제해도 브라우저에는 설정이 유지된다.
  • Chrome의 HSTS preload 리스트는 IE등 타 브라우저에서도 활용하고 있는 것으로 파악 됨
  • preload list에 추가는 신중해야 함

 

HSTS 설정 시 주의 사항

  • 서버측 redirection 처리를 별도로 하지 않았는데 https로 자동 URL이 변경되는 경우가 있다면 HSTS 헤더룰 의심
  • HSTS 헤더가 설정된 https url에 한번이라도 접속하면, HTTP 접속시에도 HTTPS로 접속됨
  • Spring Security에서 디폴트로 HTTPS 요청시에 HSTS 헤더값을 내려주도록 되어있음

 

(http://wiki.gurubee.net/display/SWDEV/HSTS+%28HTTP+Strict+Transport+Security%29)

 

 

 

728x90
반응형
320x100
728x90

283. Move Zeroes : https://leetcode.com/problems/move-zeroes/

 

Move Zeroes - 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 {
    fun moveZeroes(nums: IntArray): Unit {
        val arr = arrayListOf<Int>();
        val numList = arrayListOf<Int>();
        
        nums.forEach{
            when(it) {
                0 -> arr.add(it)
                else -> numList.add(it)
            }
        }

        //원본 배열에 덮어씌우기 
      
        val sorted = numList + arr
        
        nums.indices.forEach{
            nums[it] = sorted[it]
        }
        
    }
}
74 / 74 test cases passed.
Status: 

Accepted

Runtime: 709 ms
Memory Usage: 72.6 MB
Submitted: 6 minutes ago

 

주어지는 배열은 수정 불가 배열

수정 가능한 배열 : arrayListOf() 와 mutableListOf() 

 

indices => index value of list 

 

 

728x90
반응형
320x100
728x90

977. Squares of a Sorted Array : https://leetcode.com/problems/squares-of-a-sorted-array/

 

Squares of a Sorted 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 {
    fun sortedSquares(nums: IntArray): IntArray {
        for(i in 0 until nums.size){
            nums[i] *= nums[i];
        }
        var arr = nums.sortedArray()
        return arr
    }
}
Runtime: 574 ms, faster than 66.81% of Kotlin online submissions for Squares of a Sorted Array.
Memory Usage: 71.8 MB, less than 46.24% of Kotlin online submissions for Squares of a Sorted Array.

 

 

 

 

- 정렬 결과 배열을 반환하는 함수 : 

sortedArray() : 오름차순으로 정렬한 결과를 반환

sortedArrayDescending() : 함수는 내림차순으로 정렬한 결과를 반환

위 두 함수는 정렬 결과를 반환

 

 

- 배열에 대해 정렬만을 수행하는 함수:

sort() , sortDescending()

위 두 함수는 정렬 대상인 배열에 대하여 정렬만

728x90
반응형
320x100
728x90

35. Search Insert Position : https://leetcode.com/problems/search-insert-position/

 

Search Insert Position - 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 {
    fun searchInsert(nums: IntArray, target: Int): Int {
        var low = 0;
        var high = nums.lastIndex;
        
        while(low<=high){
            var mid = (low + high)/2;
            when{
                target == nums[mid] -> return mid
                target > nums[mid] -> low = mid + 1
                else -> high = mid - 1
            } 
        }
        return low
    }
}
Runtime: 204 ms, faster than 75.11% of Kotlin online submissions for Search Insert Position.
Memory Usage: 37.7 MB, less than 65.80% of Kotlin online submissions for Search Insert Position.
728x90
반응형
320x100
728x90

704. Binary Search : https://leetcode.com/problems/binary-search/submissions/

 

Binary Search - 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 {
    fun search(nums: IntArray, target: Int): Int {
            //nums에 특정 값 있는 지 확인
            var check = nums.contains(target) 
            if(check == true){
                var idx = nums.indexOf(target) //배열의 인덱스를 확인 
                return idx 
            }
            else{
                return -1
            }  
        }
}
Runtime: 324 ms, faster than 74.40% of Kotlin online submissions for Binary Search.
Memory Usage: 40.1 MB, less than 74.40% of Kotlin online submissions for Binary Search.

 

1)  contains : 특정 값 포함 여부를 확인

2) indexOf : 특정 데이터 인덱스 값을 확인

 

코틀린 공부하기..

728x90
반응형
320x100
728x90

leetcode 문제 : https://leetcode.com/problems/add-two-numbers/

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution(object):
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        num1,num2,total = 0,0,0
        i,j = 0,0
        
        while(l1):
            num1 += l1.val *(10 ** i)
            i += 1
            l1 = l1.next
        
        while(l2):
            num2 += l2.val *(10 ** j)
            j += 1
            l2 = l2.next
        
        total = num1 + num2
        sum_list = list(map(int, str(total)))
        
        last = None
        for num in sum_list:
            node = ListNode(num)
            node.next = last
            last = node
        
        return node
1568 / 1568 test cases passed.
Status: 

Accepted

Runtime: 87 ms
Memory Usage: 13.5 MB
Submitted: 7 hours, 4 minutes ago

 

best 풀이 

 

class Solution(object):
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        result = ListNode(0)
        result_tail = result
        carry = 0
                
        while l1 or l2 or carry:            
            val1  = (l1.val if l1 else 0)
            val2  = (l2.val if l2 else 0)
            carry, out = divmod(val1+val2 + carry, 10)    
                      
            result_tail.next = ListNode(out)
            result_tail = result_tail.next                      
            
            l1 = (l1.next if l1 else None)
            l2 = (l2.next if l2 else None)
               
        return result.next

 

완벽히 이해가..ㅜ

 

연결리스트 python 참고 : https://goforit.tistory.com/145 

728x90
반응형
320x100
728x90

쉬운거 부터..

쉬워도 다시한번

돌아보고 풀자ㅎㅎ

 

문제 : Two Sum - https://leetcode.com/problems/two-sum/

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            a = nums[i]
            for j in range(1, len(nums)):
                b = nums[j]
                if i == j:
                    continue
                if a + b == target:
                       return [i,j]

 

57 / 57 test cases passed.
Status: 

Accepted

Runtime: 8323 ms
Memory Usage: 14.9 MB

 

Hash map을 활용하여 푸는 문제.

나는 해시맵을 사용하였는가.. nope..

 

Hash map 이란?

해싱(Hashing) 된 맵(Map)

맵(Map) => 키(key)와 값(value) 두 쌍으로 데이터를 보관하는 자료구조 

 

python에서 dictionary에 해당

 

ex)

streetno = {"1": "Sachin Tendulkar", "2": "Dravid", "3": "Sehwag", "4": "Laxman", "5": "Kohli"}

 

Discuss Best 코드 참고..

class Solution:
   def twoSum(self, nums: List[int], target: int) -> List[int]:
       seen = {}
       for i, value in enumerate(nums): #1
           remaining = target - nums[i] #2
           
           if remaining in seen: #3
               return [i, seen[remaining]]  #4
           else:
               seen[value] = i  #5

쉽게 보기 위해 

    Hashmap = {}
    for index, value in enumerate(nums):
        key = target - value
        if key in Hashmap:
            return [Hashmap[key], index]
        else:
            Hashmap[value] = index

hash map에 {key:value} -> {nums:index} 형태로 저장 

 

enumerate이란?

"열거하다" 라는 뜻

enumerate 함수는 순서와 리스트 값을 전달하는 기능을 한다.

 

 

728x90
반응형