Section 18000
Prices and book list are subject to change.
Casper. Intro to Film Reader (Custom). (Required)
ISBN: 9781260238358
New: $189.50
/* | |
* 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 | |
* } | |
* } |
/** | |
* 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]() | |
} |
/** | |
* 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: |
// 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 { |
// 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 | |
*/ |
// 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); | |
} |
// 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 |