Algorithm

Algorithm/Python

프로그래머스 - 다음 큰 숫자

https://school.programmers.co.kr/learn/courses/30/lessons/12911 def oneCount(num)->int: count=0 while(num>0): if num%2==1: count+=1 num//=2 return count def solution(n): a=oneCount(n); answer=n+1 while(a != oneCount(answer)): answer+=1 return answer

Algorithm/Python

프로그래머스 - 프린터

https://school.programmers.co.kr/learn/courses/30/lessons/42587?language=python3 from collections import deque def solution(priorities, location): answer = 0 queue=deque(); for x in priorities: queue.append(x); while queue: first=queue.popleft(); if not queue or first>=max(queue): answer+=1 if location==0: return answer; else: queue.append(first); location-=1 if location

Algorithm/Java

프로그래머스 - 위장

https://school.programmers.co.kr/learn/courses/30/lessons/42578 import java.util.*; class Solution { public int solution(String[][] clothes) { int answer = 1; Map closet = new HashMap(); for(int i=0;i

Algorithm/Java

프로그래머스 - 주차 요금 계산

https://school.programmers.co.kr/learn/courses/30/lessons/92341 import java.util.*; class Solution { Map carSumTime = new TreeMap(); //누적 시간 Map carIn = new HashMap(); //입차 시간 public void calTime(int carNum, String carOut){ String[] inTime = carIn.get(carNum).split(":"); String[] outTime = carOut.split(":"); int time = (Integer.parseInt(outTime[0])-Integer.parseInt(inTime[0]))*60 +Integer.parseI..

Algorithm/Java

프로그래머스 - 숫자의 표현

https://school.programmers.co.kr/learn/courses/30/lessons/12924?language=java class Solution { public int solution(int n) { int answer = 1; for(int i=1;i

Algorithm/Python

leetcode - 2109. Adding Spaces to a String

https://leetcode.com/problems/adding-spaces-to-a-string/ class Solution: def addSpaces(self, s: str, spaces: List[int]) -> str: ans=s[:spaces[0]] for i in range(1,len(spaces)): ans+=" "+s[spaces[i-1]:spaces[i]]; ans+=" "+s[spaces[len(spaces)-1]::] return ans; 시간이나 메모리나 효율이 그닥인 방법이라... 좀 더 효율적으로 써야 할 듯

Algorithm/Java

leetcode - 11. Container With Most Water

https://leetcode.com/problems/container-with-most-water/ class Solution { public int maxArea(int[] height) { int ww=0; int templeft=0, tempright=height.length-1; while(templeftww){ ww=x;} if (height[tempright]

Algorithm/Java

leetcode - Reverse Integer

https://leetcode.com/problems/reverse-integer/submissions/ class Solution { public int reverse(int x) { boolean minus = false; long ans=0; if(x0){ int temp=x%10; x/=10; ans=ans*10+temp; } if (ans Integer.MAX_VALUE) return 0; return (minus)? (int)-ans: (int)ans; } }

Algorithm/Java

leetcode - Zigzag Conversion

https://leetcode.com/problems/zigzag-conversion/submissions/ class Solution { public String convert(String s, int numRows) { int group=(numRows-2)*2+2; if(numRows

Algorithm/Java

leetcode - add two numbers

https://leetcode.com/problems/add-two-numbers/submissions/ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode ans = new ListNode(); Li..

yoursin
'Algorithm' 카테고리의 글 목록 (21 Page)