전체 글(334)
-
[Leetcode]443. String Compression(x)
1. problem : https://leetcode.com/problems/string-compression/description/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 : class Solution: def compress(self, chars: List[str]) -> int: if not chars: return 0 write_index = 0 read_index = 0 n = len(chars) while read_index 1: for digit in str(count): ..
2024.07.28 -
[Leetcode]2942. Find Words Containing Character
1. problem : https://leetcode.com/problems/find-words-containing-character/ 2. solution 1 : class Solution { public List findWordsContaining(String[] words, char x) { List result = new ArrayList(); for (int i = 0; i 이 방법은 import java.util.List;를 불러와서 List result = new ArrayList ();를 활용해서, 문제를 풀었다. 기존의 int [] result = new int []로 하면 동적배열이 힘들어져, 이 방법을 쓰는 것이다.
2024.07.28 -
[BOJ]2231번 분해합
1. problem : https://www.acmicpc.net/problem/2231 2. solution 1 : #%%int_num = int(input()) # 216을 input으로 넣는다고 가정init_num = -1for i in range(0,int_num): str_num = str(i) sol1_sum = i for j in str_num: sol1_sum += int(j) if sol1_sum == int_num: init_num = i break print(init_num)그냥 0부터 input num까지 brute force를 적용하고 있다. 3. solution 2 : N = int(input()) # 예: 2..
2024.07.27 -
python linux terminal에서 실행
conda를 활용하는 경우, conda activate 으로 설정해 주고, interpreter도 그에 맞게 설정 sys.stdin.read를 사용하는 경우, control d 누르면 종료됨
2024.07.27 -
[Leetcode]1470. Shuffle the Array(O)
1. problem : https://leetcode.com/problems/shuffle-the-array/description/ 2. solution 1 : class Solution { public int[] shuffle(int[] nums, int n) { int[] ans = new int[nums.length]; for (int i = 0; i ans짝수번째는 nums [i]를 ans홀수번째는 nums [i+n]을 설정해 주면 된다. (은근히 헷갈림) 3. solution 2 : class Solution { public int[] shuffle(int[] nums, int n) { int[] temp = new int[2*n]; ..
2024.07.27 -
[Leetcode]300. Longest Increasing Subsequence(x)
1. problem : https://leetcode.com/problems/longest-increasing-subsequence/description/ 2. solution 1 : import java.util.Arrays;class Solution { public int lengthOfLIS(int[] nums) { int n = nums.length; int[] dp = new int[n]; Arrays.fill(dp, 1); // 각 위치에서 최소 길이는 1 for (int i =1;i nums[j]) { dp[i] = Math.max(dp[j]+1,dp[i]); } ..
2024.07.27