Skip to content

Instantly share code, notes, and snippets.

@wszdwp
wszdwp / LCMergeIntervals.swift
Last active April 14, 2019 15:03
56. Merge Intervals
/*
* Definition for an interval.
* public class Interval {
* public var start: Int
* public var end: Int
* public init(_ start: Int, _ end: Int) {
* self.start = start
* self.end = end
* }
* }
@wszdwp
wszdwp / LC120Solution.swift
Created April 14, 2019 14:44
129. Sum Root to Leaf Numbers
/**
* Definition for a binary tree node.
* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var dict = [Int: Int]()
for i in 0 ..< nums.count {
if (dict[target - nums[i]] != nil) {
return [dict[target - nums[i]]!, i]
}
dict[nums[i]] = i
}
return [Int]()
}
@wszdwp
wszdwp / ctcs_textbooks.md
Created March 26, 2019 15:29
CTCS - Cinema and Media Study Program Textbooks

CTCS - Cinema and Media Study Program

Introduction to Cinema

Section 18000

Book List

Prices and book list are subject to change. Casper. Intro to Film Reader (Custom). (Required)
ISBN: 9781260238358
New: $189.50

@wszdwp
wszdwp / LC1014.java
Created March 24, 2019 16:17
1014. Capacity To Ship Packages Within D Days
/**
* A conveyor belt has packages that must be shipped from one port to another within D days.
*
* The i-th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.
*
* Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.
*
*
*
* Example 1:
@wszdwp
wszdwp / iOSCodeGist.swift
Last active June 28, 2019 16:06
Swift gist
// multithread
// 1. GCD
DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {
var data:Data?
if let imageURL = URL(string: imageURLStr) {
data = try? Data(contentsOf: imageURL)
}
DispatchQueue.main.async(execute: {
if data == nil {
@wszdwp
wszdwp / AndroidViewUtil.java
Last active July 3, 2019 15:32
Android View Util
// Set dynamic height of a listview
setupListViewHeight(context, myListView, myListData.size(), 30); // 30 dp per row
/**
* Setup listview height based on the number of rows and unit row height
*
* @param listView
* @param numberOfRows float
* @param rowHeightInDp
*/
@wszdwp
wszdwp / UtilCodeGist.java
Created December 25, 2018 19:08
some smart code
// shift a char
s[i] = (s[i] - 'a' + shift) % 26 + 'a';
// flip upper to lower alphabeta or vice versa
// ascii code 'A': 65, 'a': 97
// 97 - 32 = 65, flip 5th binary bit means minus or plus 32
// bitwise XOR can flip to opposite bit: 1 ^ 1 = 0, 1 ^ 0 = 1,
s[i] ^= 32;
s[i] ^= 1 << 5;
class WordBreakII {
// 1. dfs with memo
private Map<String, List<String>> memo;
public List<String> wordBreak(String s, List<String> wordDict) {
List<String> ans = new ArrayList<>();
Set<String> set = new HashSet<>(wordDict);
memo = new HashMap<>();
return wordBreak(s, set);
}
@wszdwp
wszdwp / HandlerThread.java
Last active December 13, 2018 18:00
handlerThread example
// start action when thread start
HandlerThread handlerThread = new HandlerThread("printingThread") {
@Override
protected void onLooperPrepared() {
super.onLooperPrepared();
// TODO: my action
}
};
handlerThread.start(); // this will trigger onLooperPrepared