前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >包子大道消息-无人车烧钱榜单-FB开人-我们是东亚病夫? -Leetcode solution 243

包子大道消息-无人车烧钱榜单-FB开人-我们是东亚病夫? -Leetcode solution 243

作者头像
包子面试培训
发布2020-02-25 09:04:33
4910
发布2020-02-25 09:04:33
举报
文章被收录于专栏:包子铺里聊IT包子铺里聊IT

包子小道消息@02/08/2020

能够在无人车领域工作可能是很多程序员的梦想,极具挑战的技术问题,业界顶配的薪资以及关于无人驾驶未来无尽的想象空间。那么问题来了,你应该去哪家无人车公司效力呢?我一个散步小道消息的怎么会知道? 但是包子君知道钱包不鼓的公司一定都是耍流氓的公司,那么谁家的爸鼻更有钱呢?

下图是几家公司目前为止烧的钱,钱包厚度,一目了然。几点补充

  • Waymo(Alphabet), Cruise(GM) and Uber 执拗的证明二八理论,大家一共烧了16B美刀,三家烧了 一半多(只要能烧钱的事儿好像Uber都没有落下,怎么能这么牛逼呢)
  • 请注意,烧钱多不一定做出来的效果好,好比地主家的阔少爷如果不异常努力大概率是拼不过佃农家聪明勤奋的泥腿子,一个是竞争,一个是战争,不在一个量级。当然,如果地主家的富二代又努力又勤奋,祝贺(s)he! 国之栋梁
  • 你看,谷哥还是你哥,遥遥领先。注意,Nuro和Pony都表现不俗。还有,drive.ai已经被苹果收了,对,就是你们的最强大脑Ng老师的那个公司 (注:此图是不需要人工干预可以开的英里数,随手一引用,并没有核实,因为还需要给加州dmv发封邮件要数据,包子君懒的同时也不太相信dmv的速度, https://thelastdriverlicenseholder.com/2019/02/13/update-disengagement-reports-2018-final-results/, 就暂且相信他们了)
  • 包子君总结了2019到至今一年多一年的时间内加州DMV收到的无人车出事故数据,印证了了那句古话,人在江湖飘,怎能不挨刀(我想起了曾经有一个很水的印度姐姐同事,说她今年perf应该很牛逼,一个outage都没弄出来,¿Qué? ,你都没写几行代码,当然没有outage了,不求有功但求无过这种想法在程序员身上并不适用)https://www.dmv.ca.gov/portal/dmv/detail/vr/autonomous/autonomousveh_ol316
  • 没有包括一些小的但是非常有前(钱)途的startup,包括国人领先的Pony.ai, 清一色清华北大哈佛MIT领衔的Nuro,毕竟财务暂不公开,难以得知内幕。
  • 股票成功转成币圈趋势的特斯拉也不算,autopilot program打了个擦边球
  • 那么钱都怎么烧了?主要是工资和期权,同学们,行动起来吧!

写了太多,有点严谨了,不过小道消息也不能造谣你说是不是?你看那个FB的那个“小铮在硅谷”不就是发了个造谣的视频被脸书fire了嘛

还有个沙雕在华盛顿邮报上面说中国人都是东亚病夫,我希望您老能be respectful而且基于事实,在一个国家莅临磨难的时候为了吸引眼球, 也别怪我去骂你丫的 https://twitter.com/wrmead/status/1224483408807546882

Leetcode solution 243: Shortest Word Distance

Blogger:https://blog.baozitraining.org/2020/02/leetcode-solution-243-shortest-word.html

Youtube: https://youtu.be/0BvmC_JXySg

博客园: https://www.cnblogs.com/baozitraining/p/12100071.html

B站: https://www.bilibili.com/video/av80686932/

Problem Statement

Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.

Example:

Assume that words = ["practice", "makes", "perfect", "coding", "makes"].

代码语言:javascript
复制
Input: word1 = “coding”, word2 = “practice”
Output: 3
代码语言:javascript
复制
Input: word1 = "makes", word2 = "coding"
Output: 1

Note:

You may assume that word1 does not equal to word2, and word1 and word2 are both in the list.

Problem link

Video Tutorial

You can find the detailed video tutorial here

  • Youtube
  • B站

Thought Process

It is a bit confusing at first to be confused with the "Edit Distance" problem. However, there are duplicate words in the array, it's just a matter of finding the minimum distance between two words, where words could be found in multiple places in the array.

Brute force way (for each word, find the closest distance with the other word) would give you O(N^2) time complexity where N is the array size. An O(N) optimization would be having two indices for each word and keep updating the minimum distance. It is greedy because the closer the two elements are, the smaller the distance would be.

You can refer to Leetcode official solution for a detailed explanation.

Solutions

代码语言:javascript
复制
 1 public int shortestDistance(String[] words, String word1, String word2) {
 2     if (words == null || words.length == 0 || word1 == null || word2 == null || word1.equals(word2)) {
 3         return -1;
 4     }
 5     int minDistance = words.length;
 6 
 7     int wordIndex1 = -1;
 8     int wordIndex2 = -1;
 9 
10     for (int i = 0; i < words.length; i++) {
11         if (words[i].equals(word1)) {
12             wordIndex1 = i;
13             if (wordIndex2 != -1) {
14                 minDistance = Math.min(minDistance, Math.abs(wordIndex1 - wordIndex2));
15             }
16         }
17         if (words[i].equals(word2)) {
18             wordIndex2 = i;
19             if (wordIndex1 != -1) {
20                 minDistance = Math.min(minDistance, Math.abs(wordIndex1 - wordIndex2));
21             }
22         }
23     }
24 
25     return minDistance;
26 }
Implementation

Time Complexity: O(N) where N is the array size

Space Complexity: O(1) Constant space

References

  • Leetcode official solution
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-02-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 包子铺里聊IT 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 包子小道消息@02/08/2020
  • Problem Statement
  • Video Tutorial
  • Thought Process
  • Solutions
    • Implementation
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档