Algorithm/LeetCode

    [LeetCode] Minimum Number of Operations to Move All Balls to Each Box

    You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes. Return an array answer of size n, where answer[i] is the min..

    [LeetCode] Jewels and Stones

    You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A". Example 1: Input: jewels = "aA", stones = "aAAbbbb" Output: 3 Example ..

    [LeetCode] Kids With the Greatest Number of Candies

    여분의 사탕으로 사탕을 가장 많이 가진 아이와 같은 수의 사탕을 만들 수 있는 경우의 수를 구하라는 문제 Given the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has. For each kid check if there is a way to distribute extraCandies among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of cand..

    [LeetCode] Number of Good Pairs

    Given an array of integers nums. A pair (i,j) is called good if nums[i] == nums[j] and i

    [LeetCode] Kids With the Greatest Number of Candies

    import java.util.*; class Solution { public List kidsWithCandies(int[] candies, int extraCandies) { int max = candies[0]; for (int i = 0; i max){ max = candies[i]; } } ArrayList result = new ArrayList(candies.length); for (int i = 0; i = max) { result.add(true); } else { result.add(false); } } retur..

    [LeetCode] Richest Customer Wealth

    You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ customer has in the j​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth. class Solution { public int maximumWealth(int..