일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 알고리즘
- invert Binary Tree
- two pointers
- 맛집
- Array
- 망원 밥집
- 코딩 테세트
- 사당돈
- 해물감성포차
- java
- tree
- 코딩 테스트
- Find the Duplicate Number
- 6월 첼린지
- 알탕뚝배기
- 코테
- linked list
- 발리인망원
- 른당사피
- string
- 발리 음식
- findDulicate
- algorithum
- LeetCode
- 투포인터
- two sum
- Python
- prefix sum
- algorithm
- map
- Today
- Total
목록알고리즘 (11)
기록하는 공간
Reverse Linked List - LeetCode Reverse Linked List - Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: [https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg] Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: [https://asset leetcode.com # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # sel..
Is Subsequence - LeetCode Is Subsequence - Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing th leetcode.com class Solution: def isSubsequence(self, s: str, t: str) -> bool: l, r = 0, 0 while l < len(s) and r < ..
Isomorphic Strings - LeetCode Isomorphic Strings - Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving th leetcode.com class Solution: def isIsomorphic(self, s: str, t: str) -> bool: for a,b in zip(s, t): if s.index(a..
https://leetcode.com/problems/find-pivot-index/ class Solution: def pivotIndex(self, nums: List[int]) -> int: total_sum = sum(nums) for i in range(0, len(nums)): target = sum(nums[:i]) if target == (total_sum - nums[i] - target): return i return -1
https://leetcode.com/problems/running-sum-of-1d-array/ prefix sum 알고리즘을 활용한 문제 풀이 import copy class Solution: def runningSum(self, nums: List[int]) -> List[int]: sum_arr = [nums[0]] for i in range(1, len(nums)): sum_arr.append(sum_arr[i - 1] + nums[i]) return sum_arr
문제링크 leetcode.com/problems/merge-strings-alternately/ Merge Strings Alternately - 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: def mergeAlternately(self, word1: str, word2: str) -> str: res = '' arr1 = list(word1) arr2 = list(word2) maxLenght = max(len(word1), le..
문제링크 leetcode.com/explore/challenge/card/march-leetcoding-challenge-2021/588/week-1-march-1st-march-7th/3657/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 답안 1) /** candyType / 2를 하여 먹을 수 있는 사탕 갯수를 구한다. candyType을 Se..
문제 링크 leetcode.com/problems/consecutive-characters/ Consecutive Characters - 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 maxPower(s: String): Int { var maxResult = 0 val charArray = s.toCharArray() val charArraySize = s.toCharArray().size for (i in 0 unt..
class Solution { private fun swap (first: Int, second: Int, nums: IntArray) { val temp = nums[first] nums[first] = nums[second] nums[second] = temp } fun moveZeroes(nums: IntArray): Unit { var first = 0 var second = 0 val numsSize = nums.size while (first < numsSize) { if (nums[first] != 0) { swap(first, second, nums) second++ } first++ } } }
Map을 이용한 풀이 class Solution { public int findDuplicate(int[] nums) { int duplicateNumber = 0; int numsLength = nums.length; Map map = new HashMap(); for (int i : nums) { map.put(i, map.getOrDefault(i, 0) + 1); if (map.get(i) > 1) duplicateNumber = i; } return duplicateNumber; } }