본문 바로가기
728x90

전체 글163

leetcode 382) Linked List Random Node LV. Medium 🧐 https://leetcode.com/problems/linked-list-random-node/ Linked List Random Node - 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 문제 Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. .. 2022. 1. 8.
cpp 난수 생성 (random number generation) : PRNG 컴퓨터는 일반적으로 난수를 생성할 수 없음!! 그래서 의사 난수 생성기를 통해 난수 생성 코드를 짜 보자👊 의사 난수 생성기(pseudo-random number generator: PRNG) 시드(seed)라고 하는 시작 번호를 가지고 시드와 전혀 다른 번호로 변환하기 위해 수학 연산을 수행하는 프로그램 곱하기와 더하기 같은 수학 연산을 통해 오버플로우를 발생시켜 난수를 만든다! // 벡터의 인덱스의 값을 난수로 받을것이기에 unsigned int 사용! unsigned int PRNG(unsigned int range) { // 처음 시드는 큰 수(오버플로우가 날 수 있도록)로 임의로 지정 // static으로 seed를 두어 계산되어있는 시드를 재사용할 수 있도록 함 -> 난수가 동일하게 나오는 것.. 2022. 1. 8.
leetcode 143) Reorder List LV. Medium 🧐 https://leetcode.com/problems/reorder-list/ Reorder List - 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 문제 You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln.. 2022. 1. 6.
leetcode 231) Power of Two LV. Easy 😎 https://leetcode.com/problems/power-of-two/ Power of Two - 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 문제 Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x... 2022. 1. 5.
leetcode 416) Partition Equal Subset Sum LV. Medium 🧐 https://leetcode.com/problems/partition-equal-subset-sum/ Partition Equal Subset Sum - 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 문제 Given a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the.. 2022. 1. 4.
leetcode 221) Maximal Square LV. Medium 🧐 https://leetcode.com/problems/maximal-square/ Maximal Square - 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 문제 Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example 1: Input: matrix = [["1","0".. 2022. 1. 4.
cpp 멤버 이니셜라이저(Member Initializer) cpp에서는 멤버 이니셜라이저를 지원! 멤버 이니셜라이저가 뭘까? 멤버(member) = 클래스 내의 멤버 변수 이니셜라이저(initializer) = 초기화 멤버 이니셜라이저 = 클래스가 생성되면서 바로 멤버 변수를 초기화해주는 것 멤버 이니셜라이저가 왜 생겼을까!? 멤버 이니셜라이저가 있기 전에는 밑에 코드와 같이 생성자 안에서 변수를 초기화해줘야 했다 class A { private: int a; public: A(int _a) { a = _a; } } 이렇게 생성자를 통해서 멤버 변수를 초기화하는 것은 불편하기에 멤버 이니셜라이저(Member Initializer) 필요! 멤버 이니셜라이저의 장점 1. 초기화의 대상을 명확히 인식이 가능 2. 선언과 동시에 초기화가 이뤄지는 바이너리 코드가 생성되.. 2022. 1. 3.
cpp static const 변수 c++98으로만 코드를 짜는 중에 발생한 오류! error: default member initializer for non-static data member is a C++11 extension [-Werror,-Wc++11-extensions] 클래스 안에서 변수 초기화는 c++11부터 지원해준다!😱 class A { private: int a = 0; } 이렇게 쓰는 것이 불가능!! c++98에서 static const 변수에는 클래스 안에서 초기화가 가능! 그렇다면 static const는 왜 클래스 안에서 초기화가 가능할까!? static 변수란? 객체들이 생성될 때마다 생성되는 것이 아닌, 클래스가 정의되기 이전(프로그램 시작과 끝까지)부터 메모리에 할당된 변수 = 클래스 변수(클래스 당 하나씩.. 2022. 1. 3.
티스토리 블로그 검색 설정 보호되어 있는 글 입니다. 2022. 1. 3.
728x90