Skip to content

Instantly share code, notes, and snippets.

View dailybird's full-sized avatar
🏠
Working from home

杨宁 dailybird

🏠
Working from home
View GitHub Profile
package com
import scala.collection.mutable
import scala.io.Source
object NonDivisibleSubset {
def main(args: Array[String]): Unit = {
val target = Source.fromFile("").mkString.split(" ").map(_.toInt)
println(target.length)
def appendAndDelete(s: String, t: String, k: Int): String = {
val sLength = s.length
val tLength = t.length
val minLength = Math.min(sLength, tLength)
var done = false
var index = 0
while (done == false && index < minLength) {
if (s(index).equals(t(index)) == false) {
done = true
} else {
package com
import scala.collection.mutable.ArrayBuffer
object MagicSquare {
def main(args: Array[String]): Unit = {
val target = Array[Array[Int]](
Array[Int](4, 8, 2),
@dailybird
dailybird / Permutation.scala
Created July 8, 2018 09:36
Select all permutations of N elements from the collection.
package com
import scala.collection.mutable.ArrayBuffer
object PermutationQuestion {
def main(args: Array[String]): Unit = {
val candidates = ArrayBuffer[Int](1, 3, 7, 5, 9)
val count = 3
val container = getAllPermutations(count, candidates)
@dailybird
dailybird / PatternQuestion.java
Created July 3, 2018 04:43
字符串匹配模式问题
package com;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Pattern;
public class PatternQuestion {
@dailybird
dailybird / Combination.scala
Last active July 8, 2018 09:36
Select all combinations of N elements from the collection.
package com
import scala.collection.mutable.ArrayBuffer
object CombinationQuestion {
def main(args: Array[String]): Unit = {
val candidates = ArrayBuffer[Int](1, 3, 7, 5, 9)
val count = 3
val container = getAllCombinations(count, candidates)
@dailybird
dailybird / nodes_to_tree.php
Created June 2, 2017 00:17
Resolve nodes to tree.
<?php
/**
* Created by PhpStorm.
* User: dailybird
* Date: 17/6/1
* Time: 下午11:57
*/
$nodes = [
@dailybird
dailybird / add.php
Created April 8, 2017 15:15
Simple message borad.
<?php
date_default_timezone_set('PRC');
$filename = 'messages.txt';
$username = $_POST['username'] ?? null;
$title = $_POST['title'] ?? null;
$content = $_POST['content'] ?? null;
if(!is_null($username) && !is_null($title) && !is_null($content)){
@dailybird
dailybird / number_of_1_in_binary.c
Created April 7, 2017 03:28
Find the number of 1 in binary.
int upperBit(x)
{
int count = 0;
while(x)
{
count++;
x = x & (x-1);
}
return count;
}
@dailybird
dailybird / pyramid-printer.php
Last active April 1, 2017 14:30
Print a pyramid.
<?php
/**
* 打印金字塔
* @param [int] $level [层数]
* @return [void]
*/
function pyramidPrinter($level){
for ($index = 1; $index <= $level; $index++) {
for ($space = $level; $space > $index; $space--) {