Algorithm、Review、Tip、Share
1.每周至少做一个 leetcode 的算法题
1. Two Sum
int* twoSum(int* nums, int numsSize, int target) {
static int targetArray[2] = {0};
for(int i = 0; i < numsSize - 1; i++){
for(int j = i + 1; j < numsSize; j++){
if(nums[i] + nums[j] == target){
targetArray[0] = i;
targetArray[1] = j;
return targetArray;
}
}
}
return 0;
}
class Solution {
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var dict = [Int:Int]()
for index in 0..<nums.count {
dict[nums[index]] = index
}
for i in 0..<nums.count {
var complement = target - nums[i]
if let complementIndex = dict[complement] {
if complementIndex == i {
continue
} else {
return [i,complementIndex]
}
}
}
return []
}
}
2.阅读并点评至少一篇英文技术文章
最近决定开始学习应用swift到项目中,所以搜了一篇switf学习到应用的文章。
100 Days of Swift: The Tutorials
作者Sam Lu
表示switf非常容易学习,但是要应用到项目中却要解决很多的问题才行,为了分享经验Sam lu花费了6个月专门做了关于swift应用指导的多媒体视频。
“Fundamentals, fundamentals, fundamentals. You’ve got to get the fundamentals down otherwise the fancy stuff isn’t going to work.” ―Randy Pausch, The Last Lecture
对于switf的版本更新,Sam引用了上面的话表达观点。
- How do I structure my code?
- Why write a function?
- What’s the use case of a variable?
- How do I detect when a user taps a button?
- How do I build a user interface?
最后,Sam建议swift学习到应用的过程中,常思考这些问题能快速应用到项目中来。
网友评论