Cindy's Blog

アマゾンで働いているエンジニアの日常

2022-10-11から1日間の記事一覧

LeetCode 283. Move Zeroes

Follow up: Could you minimize the total number of operations done? https://leetcode.com/problems/move-zeroes/ //firstZeroIndex -> z // z: -1 // i //[1,3,12,0,0] //when nums[i] = 0 //if z = -1, then z = i //else //if z != -1 (had zero in fr…

LeetCode 200. Number of Islands

UnionFind island count direction https://leetcode.com/problems/number-of-islands/ class Solution { public int numIslands(char[][] grid) { int rows = grid.length; int cols = grid[0].length; int countIslands = 0; int[][] directions = {{0, 1}…

LeetCode 392. Is Subsequence

Easy question https://leetcode.com/problems/is-subsequence/ class Solution { public boolean isSubsequence(String s, String t) { int sIndex = 0; int tIndex = 0; while (sIndex < s.length() && tIndex < t.length()){ //"abc" // s //"ahbcgd" // …