2023年9月6日 星期三

CSS values and units

https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units 



UnitNameEquivalent to
cmCentimeters1cm = 37.8px = 25.2/64in
mmMillimeters1mm = 1/10th of 1cm
QQuarter-millimeters1Q = 1/40th of 1cm
inInches1in = 2.54cm = 96px
pcPicas1pc = 1/6th of 1in
ptPoints1pt = 1/72nd of 1in
pxPixels1px = 1/96th of 1in

2023年8月24日 星期四

[Java] Partition equal subset sum

 class Solution {

    public boolean canPartition(int[] nums)
    {
        int n = nums.length;
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            sum+=nums[i];
        }
       
        if(sum%2 !=0 ) return false;

        sum = sum/2;
        boolean[][] possible = new boolean[n+1][sum+1];
        for(int i=0; i<=n; i++) possible[i][0] = true;

        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=sum; j++)
            {
                if(nums[i-1] > j)
                {
                    possible[i][j] = possible[i-1][j];
                }
                else
                {
                    possible[i][j] = possible[i-1][j-nums[i-1]] || possible[i-1][j];
                }
            }
        }
        return possible[n][sum];
    }
};


[Java] Next Permutation

 class Solution {


    public boolean nextPermutation(int[] nums) {

        int ind1=-1;

        int ind2=-1;

        // step 1 find breaking point 

        for(int i=nums.length-2;i>=0;i--){

            if(nums[i]<nums[i+1]){

                ind1=i;

                break;

            }

        }

        // if there is no breaking  point 

        if(ind1==-1){

            reverse(nums,0);

return false;

        }

        

        

// step 2 find next greater element and swap with ind2

for(int i=nums.length-1;i>=0;i--){

if(nums[i]>nums[ind1]){

ind2=i;

break;

}

}


swap(nums,ind1,ind2);

// step 3 reverse the rest right half

reverse(nums,ind1+1);

        return true;

    }

    void swap(int[] nums,int i,int j){

        int temp=nums[i];

        nums[i]=nums[j];

        nums[j]=temp;

    }

    void reverse(int[] nums,int start){

        int i=start;

        int j=nums.length-1;

        while(i<j){

            swap(nums,i,j);

            i++;

            j--;

        }

    }

}

2023年7月19日 星期三

[Java] Rotate matrix clockwise in place

 class Solution {

    public void rotate(int[][] matrix) {

        int a=0,b=matrix.length-1,tmp;

        while(a<=b)

        {

            for(int k=0;k<=b-a-1;k++)

            {

                tmp = matrix[a][a+k];

                matrix[a][a+k] = matrix[b-k][a];

                matrix[b-k][a] = matrix[b][b-k];

                matrix[b][b-k] = matrix[a+k][b];

                matrix[a+k][b] = tmp;

            }

            a++;

            b--;

        }


    }

}

2023年3月31日 星期五

CSS Battle #104 Amegakure

 <div a></div><div b></div><div c></div><div d></div><div e></div><div f></div><style>body{background:#000}

div{position:absolute;left:50%;top:50%}

div[a]{background:#37385A;width:240;height:120;border-radius:20px;transform:translate(-50%,-50%)}

div[b]{background:#9897AE;width:200;height:80;border-radius:10px;transform:translate(-50%,-50%)}

div[c]{background:#000;width:10;height:10;border-radius:10px;transform:translate(-85px,-50%);box-shadow:0 -20px #000,0 20px #000,160px 0 #000,160px -20px #000,160px 20px #000}

div[d]{background:#C0C3DB;width:51;height:80;transform:translate(-50%,-50%) skew(-15deg,0deg)}

div[e]{background:#000;width:10;height:50;border-radius:10px;transform:translate(-35px,-50%);box-shadow:20px 0 #000,40px 0 #000,60px 0 #000}

CSS Battle #106 Ryuk's Apple

 <div a></div><div b></div><div c></div><div d></div><div e></div><div f></div><style>body{background:#000}

div{position:absolute;left:50%;top:50%}

div[a]{background:#D4392D;width:100;height:120;border-radius:50%;transform:translate(-20px,-60px) rotate(30deg)}

div[b]{background:#D4392D;width:100;height:120;border-radius:50%;transform:translate(-80px,-60px) rotate(-30deg)}

div[c]{background:#000;width:60;height:70;border-radius:50%;transform:translate(-111px,-54px) rotate(45deg)}

div[d]{background:#000;width:60;height:70;border-radius:50%;transform:translate(-111px,-14px) rotate(45deg)}

div[e]{background:#D4392D;width:10;height:70;transform:translate(-50%,-80px)}

CSS Battle #100 Beo

 <div a></div><div b></div><div c></div><div d></div><div e></div><div f><div g></div></div><div h></div><div i></div><div j></div><div k></div><div l></div>

<style>body{background:#14313E}

div{position:absolute;left:50%;top:50%}

div[a]{background:#FFDF00;width:294;height:40;border-radius:5px;transform:translate(-50%,-50%)}

div[b]{background:#FFDF00;width:274;height:150;border-radius:20px;transform:translate(-50%,-50%)}

div[c]{background:#14313E;width:224;height:100;border-radius:10px;transform:translate(-50%,-50%)}

div[d]{background:#14313E;width:194;height:154;transform:translate(-50%,-50%)}

div[e]{background:#FFDF00;width:30;height:154;transform:translate(-7px,-90px) rotate(45deg)}

div[f]{background:#14313E;width:50;height:154;transform:translate(-33px,-91px) rotate(-45deg)}

div[g]{background:#FFDF00;width:30;height:154;transform:translate(-50%,-50%)}

div[h]{background:#FFDF00;width:21;height:21;transform:translate(-73px,-79px);box-shadow:125px 0 #FFDF00}

div[i]{background:#FFDF00;width:20;height:80;transform:translate(-50px,-6px) rotate(-45deg)}

div[j]{background:#FFDF00;width:20;height:80;transform:translate(30px,-6px) rotate(45deg)}

div[k]{background:#FFDF00;width:20;height:80;transform:translate(-57px,2px) rotate(45deg);border-radius:18px}

div[l]{background:#FFDF00;width:20;height:80;transform:translate(37px,2px) rotate(-45deg);border-radius:18px}