顯示具有 leetcode easy 標籤的文章。 顯示所有文章
顯示具有 leetcode easy 標籤的文章。 顯示所有文章

leetcode easy - Contains Duplicate

 LeetCode


Code
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Arrays.sort(nums);


        for ( int i = 0; i < nums.length-1; i++ ) {
            if (nums[i] == nums[i+1]) return true;
        }


        return false;
    }

leetcode easy - Pascal's Triangle

LeetCode

Code

import java.util.ArrayList;
import java.util.List;


class Solution {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList<>();
        for ( int i = 0; i < numRows; i++ ) {
            List<Integer> row = new ArrayList<>();
            for ( int j = 0; j <= i; j++ ) {
                if (i == 0 || i == 1 || j == 0 || i == j) {
                    row.add(1);
                    continue;
                }


                System.out.println("(" + i + "," + j + ")");
                row.add(result.get(i-1).get(j-1) + result.get(i-1).get(j));
            }
            result.add(row);
        }
        return result;
    }


LeetCode - Kids With the Greatest Number of Candies

 

LeetCode

Code
class Solution {
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        int max = max(candies);
        List<Boolean> result = new ArrayList<>();
        for (int i = 0; i < candies.length; i++) {
            result.add(candies[i] + extraCandies >= max);
        }
        return result;
    }
    
    private int max(int[] candies) {
        int max = 0;
        for ( int i = 0; i < candies.length; i++ ) {
            if (max < candies[i]) {
                max = candies[i];
            }
        }
        return max;
    }
}

leetcode - Shuffle the Array

 

LeetCode

Code
class Solution {
    public int[] shuffle(int[] nums, int n) {
        int[] result = new int[nums.length];
        int currentIdx = 0;
        for (int i = 0; i < n; i++) {
            result[currentIdx] = nums[i];
            result[currentIdx+1] = nums[i+n];
            currentIdx += 2;
        }
        return result;
    }
}

leetcode - Running Sum of 1d Array

 

LeetCode

Code
class Solution {
    public int[] runningSum(int[] nums) {
        int[] result = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                result[i] = nums[i];
            } else {
                result[i] = result[i-1] + nums[i];
            }
        }
        return result;
    }
}

Lessons Learned While Benchmarking vLLM with GPU

Recently, I benchmarked vLLM on a GPU to better understand how much throughput can realistically be expected in an LLM serving setup. One ...