Skip to content

Instantly share code, notes, and snippets.

View Allan-Gong's full-sized avatar

Allan Gong Allan-Gong

  • Facebook
  • Seattle, US
View GitHub Profile
package test;
// The key observation is that in order to win Tic-Tac-Toe you must have the entire row or column.
public class DesignTicTacToe {
class TicTacToe {
int[] rows;
int[] cols;
private List<String> bfs(Map<String, Set<String>> graph, Set<String> visited, String start) {
if (visited.contains(start)) return Collections.emptyList();
List<String> emails = new ArrayList<>();
Queue<String> queue = new LinkedList<>();
queue.offer(start);
visited.add(start);
while (!queue.isEmpty()) {
int size = queue.size();
BFS
visited = {}
// initialize
queue = [a]
current_size = 0
offsets = [[0,1],[0,-1],[1,0],[-1,0]]
@Allan-Gong
Allan-Gong / gist:c3d5a459873bb72e8f535ddbc3ce646c
Created September 27, 2024 02:42
changeset for changing a rum application name
[
{
"type": "Resource",
"resourceChange": {
"policyAction": "ReplaceAndDelete",
"action": "Modify",
"logicalResourceId": "TestAppMonitor",
"physicalResourceId": "TestAppMonitor",
"resourceType": "AWS::RUM::AppMonitor",
"replacement": "True",
@Allan-Gong
Allan-Gong / gist:eca531dc82152441383e383456ed492c
Created April 1, 2024 21:36
CloudWatchAgentServerPolicy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CWACloudWatchServerPermissions",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeVolumes",
"ec2:DescribeTags",
@Allan-Gong
Allan-Gong / gist:5532d2b950f148f1d83d3039db816fcb
Created April 1, 2024 21:35
CloudWatchAgentAdminPolicy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CWACloudWatchPermissions",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeTags",
"logs:PutLogEvents",
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/runtime-db3ced03541c6a1dba73.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/pages-074ae03aaa397e157edc.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/nodes-empty-states-image-chrome-f42fa5df0e74c8aaa91c.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/dialogs-678c6bdbd3b98c546e3a.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/jquery-lodash-3809ac86f28ed37b84b5.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/clouddrive-flux-adapters-1981fc80a7972ac1ec20.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/moment-92a69cf17837993ab7e3.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/react-virtualized-f223c90cce2a7c654658.js'></script>
<script crossorigin='anonymous' sr
/**
* 2. 給兩個相同長度的integer array, 分別表示從A城市到B城市每天去程和回程的票價.
* 要找出來回票價加總最便宜是多少,規定不能同天來回, 回程要在去程之後.
* 舉例: departure=[10, 8, 9, 11, 7], arrival=[8, 8, 10, 7, 9],
* 那結果是15 (departure[1] + arrival[3] = 8 + 7 = 15)
*/
public class CheapestFlights {
public int cheapeast(int[] from, int[] to) {
}
class Solution {
public int longestOnes(int[] nums, int k) {
int n = nums.length;
int countOfZero = 0;
int longest = 0;
//. s
// [0,1,1,0,0,0,1,1,1,1,0]
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;