👩💻Developer27 [Easy][Python] Find Center of Star Graph n nodes를 가진 undirected star graph 가 존재한다. star graph는 n-1 개의 edge가 있고 가운데에 center node가 있는 형태이다. 이는 코드로 2D integer array로 주어지며 각 edges[i]는 [u_i, v_i] 형태로 두 node사이에 edge가 있음을 나타낸다. 이 graph의 center를 return 한다. EX1) edges = [[1,2],[2,3],[4,2]] #output :2 class Solution: def findCenter(self, edges: List[List[int]]) -> int: res = list(reduce(lambda i, j: i&j, (set(n) for n in edges))) #reduce를 통해서 모든.. 2022. 10. 22. [Easy][Python] Jewels and Stones jewels와 stones라는 string이 주어지고 stones의 각 character는 내가 가지고 있는 stone type을 의미한다. 내가 가지고 있는 stones중 jewels가 몇개인지 개수를 return 한다. *소문자와 대문자는 다른 stone으로 구분한다. EX1) jewels = "aA", stones="aAAbbb" => 3 class Solution: def numJewelsInStones(self, jewels: str, stones: str) -> int: count = 0; for i in range(len(jewels)): count += stones.count(jewels[i]); return count 2022. 10. 22. [Easy][Python] Count Items Matching a Rule items라는 array가 주어지며 각 items[i] 는 [type_i, color_i, name_i] 의 형태로 ith item의 type, color 그리고 item를 나타낸다. 또한 ruleKey 와 ruleValue라는 두 string형태의 rule이 주어진다. ith item이 아래 중 한가지와 매치할 경우 룰에 맞는다고 가정한다. ruleKey == "type" and ruleValue == type_i. ruleKey == "color" and ruleValue == color_i. ruleKey == "name" and ruleValue == name_i class Solution: def countMatches(self, items: List[List[str]], ruleKey: str.. 2022. 10. 22. Linked Lists란 무엇인가? * 해당 글은 학과 수업으로 배운 내용과 코드가 포함되어 있으며 개인적 공부 목적으로 업로드하였습니다. 학과 수업시간에 배운 내용을 그때그때 정리하고자 한다. 시험에도 도움이 되고 나중에 이후 무언가를 준비할때도 도움이 될듯하다 (절대 시험을 너무 망쳐서 강제로 복습하는게 아니다) Linked Lists Linked list 의 가장 큰 특징은 pointer를 통해서 다음 요소를 access할 수 있다는 것이며 각 element 를 node라고 부른다. 위 그림에서 파란색 상자 하나가 node인것이다. 위 구조에서 보듯이 next가 또다른 같은 구조의 node를 가리키고 있기 때문에 recursive하다는 특징을 가지고 있다. 코드로 구현하면 아래와 같다. typedef struct linked_node.. 2022. 10. 22. 이전 1 ··· 3 4 5 6 7 다음