ARTS - Week 3

ARTS挑战

Algorithm : 编程训练和学习 —— 每周至少做一个LeetCode算法题。

Review : 学习英文 —— 阅读并点评至少一篇英文技术文章。

Tip : 总结和归纳知识点 —— 学习至少一个技术技巧。

Share : 建立影响力,能够输出价值观 —— 分享一篇有观点和思考的技术文章。

文中涉及语言均为Python。

Algorithm

题目

28. 实现strStr()

实现 strStr() 函数。

给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。

示例 1:

输入: haystack = "hello", needle = "ll"

输出: 2

示例 2:

输入: haystack = "aaaaa", needle = "bba"

输出: -1

说明:

当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。

对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与C语言的 strstr() 以及 Java的 indexOf() 定义相符。

思路

方法一:直接遍历索引

方法二:利用内置函数index()

方法三:函数find()

代码

# 方法一:
class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        if not needle:
            return 0
        else:
            if needle in haystack:
                for i in range(len(haystack)):
                    if haystack[i:i+len(needle)] == needle:
                        break
                return i
            else:
                return -1

# 方法二:
class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        try:
            return haystack.index(needle)
        except:
            return -1
            
# 方法三:
class Solution:
    def strStr(self, haystack: 'str', needle: 'str') -> 'int':
        return (haystack.find(needle))
复制代码

时间复杂度:O(n),空间复杂度:O(1)。

Review

5 Resources to Inspire Your Next Data Science Project

The writer, Conor Dewey, talked about how to start a side project.

Side projects work best when they live at the interaction of “Things you enjoy” and “Things that help you practice a marketable skill.” - Julie Zhuo

There may be some problems with picking an specific goal of the project. A few examples:

  • Machine learning and modeling;
  • Exploratory data analysis;
  • Metrics and experimentation;
  • Data visualization and communication;
  • Data mining and cleaning

Your projects should reflect your goals (also, be enjoyable).

Find projects which is similiar with your own interests, learn from them and then generate your own new, original work that stands alone.

“Nothing is original. Steal from anywhere that resonates with inspiration or fuels your imagination.” — Jim Jarmusch

5 Resources for inspiration:

Data is Beautiful

Kaggle

The Pudding

FiveThirtyEight

Towards Data Science

Tips

对比find()函数与index()函数

find():从左向右寻找子序列的位置,如存在多个相同子序列只返回第一个查找到的位置,如果子序列不存在返回-1

rfind():从右向左寻找子序列的位置

str.find(str, beg=0, end=len(string))
复制代码

index():从左向右寻找子序列的位置,如果子序列不存在,会报错ValueError

rindext():从右向左寻找子序列的位置

str.index(str, beg=0, end=len(string))
复制代码

Share

The Third Wave Data Scientist

This article discussed about data science skill portfolio. Experimenting and innovating, efficiently seeking out business value und bridging the deployment gap to create great data products. Skills required as below:

  1. Business Mindset (core skill): set goals and apply other skills

Engineers are hired to create business value, not to program things. Likewise, data scientists are hired to create business value, not just to build models.

Know the complicated things, but do not overcomplicate things.

  1. Software Engineering Craftsmanship: “hacking skills”

  2. Statistics and Algorithms Toolbox:

Data scientists have to thoroughly understand the basic concepts in statistics and particularly in machine learning

You will often have to explain algorithms or concepts like statistical uncertainty to your clients, or red-flag an insight because of a confusion between correlation and causation.

  1. Soft Skills:

Work well with others

Understand your client

Navigate company politics

Communicate your results

Evaluate yourself

On the road of self-learning, sometimes I may feel confused and cannot figure out how far I have gone. But reading these articles would be a kind of self-checking and also strengthen my conviction. Keep doing this.


如有任何疑问或错误,欢迎指出。

转载于:https://juejin.im/post/5cb1ae88e51d456e75589ea1

你可能感兴趣的:(java,c/c++,数据结构与算法)