This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static int minimumSwaps(int[] arr) { | |
| if (arr.length == 1) { | |
| return 0; | |
| } | |
| int swapCount = 0; | |
| int temp; | |
| for (int i = 1; i <= arr.length; i++) { | |
| if (i != arr[i-1]) { | |
| temp = arr[i-1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // you can also use imports, for example: | |
| import java.util.*; | |
| // you can write to stdout for debugging purposes, e.g. | |
| // System.out.println("this is a debug message"); | |
| class Solution { | |
| public int solution(int[] A, int[] B) { | |
| ArrayList<Integer> up_sizes = new ArrayList<>(); | |
| int lives = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int solution(int X, int[] A) { | |
| // write your code in Java SE 8 | |
| boolean[] checkArray = new boolean[X]; | |
| for(int i=0; i<A.length; i++) { | |
| boolean is_leave = checkArray[A[i] - 1]; | |
| if (is_leave == false) { | |
| checkArray[A[i]- 1] = true; | |
| X -= 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(A): | |
| sum_a = sum(A) | |
| left = A[0] | |
| right = sum_a - left | |
| min_diff = abs(right - left) | |
| for idx in range(1, len(A)-1): | |
| cur = A[idx] | |
| left += cur | |
| right -= cur |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(A): | |
| check_list = [False] * (len(A) + 1) | |
| for i in A: | |
| check_list[i-1] = True | |
| for idx, j in enumerate(check_list): | |
| if not j: | |
| return idx + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(A): | |
| check_dict = {} | |
| for i in A: | |
| is_unpaired = check_dict.get(i, False) | |
| if is_unpaired: | |
| del check_dict[i] | |
| else: | |
| check_dict[i] = True | |
| return list(check_dict.keys())[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import deque | |
| def solution(A, K): | |
| d = deque(A) | |
| d.rotate(K) | |
| return list(d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(A): | |
| min_value = 1000000 | |
| missing_list = [True] * 1000000 | |
| for num in A: | |
| if num > 0: | |
| missing_list[num-1] = False | |
| for idx, is_missing in enumerate(missing_list): | |
| if is_missing: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(N): | |
| max_length = 0 | |
| length = 0 | |
| quotient = N | |
| remainder = 0 | |
| is_occur_one = False | |
| while quotient > 0: | |
| quotient, remainder = divmod(quotient, 2) | |
| if is_occur_one: | |
| if remainder == 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def solution(progresses, speeds): | |
| days = [] | |
| for idx in range(len(progresses)): | |
| day = math.ceil((100 - progresses[idx]) / speeds[idx]) | |
| days.append(day) | |
| result = [] |
NewerOlder