Define “Straight” as 5 cards with consecutive numbers. Determine if the deck can be fully divided into sets of “Straight”. Example: 1, 2, 3, 4, 4, 5, 5, 6, 7, 8 -> TrueYou may assume the cards are sorted 这个是用一个hashtable,key是数字,value是出现次数 然后遍历原数组,每一个数…
Define “X-Straight” as X cards with consecutive numbers (X >= 3). Determine if the deck can be fully divided into sets of “X-Straight”. Example: 1, 2, 3, 4, 4, 5, 6 -> True Backtracking: package Straight; import java.util.*; public class Solution2 {…
给一个datastream和一个fixed window size, 让我design一个class可以完成add number还有find average in the window. 就是不能用vector得用array. 当然用queue是最好的 package DataStreamAverage; import java.util.*; public class Solution { int count; int sum; Queue<Integer> q; public Soluti…
第二题 算法 给你一个arr 返回 T 或者 F arr的每个数代表从这个点开始跳几部,返回T的情况:从这个arr中任意一个数开始跳,可以在每个元素都跳到且只跳到一次的情况下返回到开始跳的元素 比如[1,1,1,1,1,1] => T [0,1,1,1,1,1]=> F [7, 5, 2, 3] => F [2,2,3,1] => T. From 1poi scan array once, get the index that can be reached by each arra…
Given a sorting order string, sort the input string based on the given sorting order string. Ex sorting order string -> dfbcae Input string -> abcdeeabc output -> dbbccaaee 法一:Comparable sample Input: String order = "dfbcae"; String str…