蚂蚁退地,房价猛跌

2 阅读5分钟

蚂蚁退地,房价猛跌

2020年-2021年,蚂蚁集团先后拿下之江度假区钱塘江岸 XH1710-B1/B2-23 和 XH1708-02 地块。

一时间,"蚂蚁集团坐拥大量土地,欲打造全球总部"的消息传遍全国,之江板块房价连夜猛涨,有二手房单价从三四万元直接涨到六七万元,各路买家也闻风而动,杀到之江抢房。

但近两年,随着中概互联和国内经济的同步下行,关于"蚂蚁或将退地"的传闻此起彼伏,原因是这一总部地标一直空置。

而就在近期,蚂蚁退地的消息被正式坐实,传闻又切换为"之江板块直降百万无人问津"。

潮起潮落很好理解,但在国内房地产普遍进入"买方市场"的今天,蚂蚁退地的利空应该早就被市场消化,如今的坐实对实际房价影响会有多大呢?

通过贝壳的开放数据可以知道,之江九里同样一套 98 平的户型,两年前成交价最高近 560 万(约 57000 一平方),而今年上半年的最近成交价为 350 万(约 36000 一平方)。

由此可见,在消息坐实之前,之江板块就基本跌回蚂蚁拿地之前的水平。

对此你怎么看?

...

回归主线。

来一道和「蚂蚁金服」相关的算法题。

题目描述

平台:LeetCode

题号:809

有时候人们会用重复写一些字母来表示额外的感受,比如 "hello" -> "heeellooo", "hi" -> "hiii"。我们将相邻字母都相同的一串字符定义为相同字母组,例如:"h", "eee", "ll", "ooo"

对于一个给定的字符串 S ,如果另一个单词能够通过将一些字母组扩张从而使其和 S 相同,我们将这个单词定义为可扩张的(stretchy)。

扩张操作定义如下:选择一个字母组(包含字母 c ),然后往其中添加相同的字母 c 使其长度达到 3 或以上。

例如,以 "hello" 为例:

我们可以对字母组 "o" 扩张得到 "hellooo",但是无法以同样的方法得到 "helloo" 因为字母组 "oo" 长度小于 3。此外,我们可以进行另一种扩张 "ll" -> "lllll" 以获得 "helllllooo"

如果 S = "helllllooo",那么查询词 "hello" 是可扩张的,因为可以对它执行这两种扩张操作使得 query = "hello" -> "hellooo" -> "helllllooo" = S

输入一组查询单词,输出其中可扩张的单词数量。

示例:

输入: 
S = "heeellooo"
words = ["hello", "hi", "helo"]

输出:1

解释:
我们能通过扩张 "hello""e""o" 来得到 "heeellooo"。
我们不能通过扩张 "helo" 来得到 "heeellooo" 因为 "ll" 的长度小于 3 。

提示:

  • 0<=len(S)<=1000 <= len(S) <= 100
  • 0<=len(words)<=1000 <= len(words) <= 100
  • 0<=len(words[i])<=1000 <= len(words[i]) <= 100
  • S 和所有在 words 中的单词都只由小写字母组成。

双指针

该题最难的部分就是理解 “扩张” 操作:假设有两个字符相同的连续段 ab,如何判断 a 是否能由 b 扩张而来。

忘记掉题目所说的规则,我们重新定义 “扩张” 操作:

  • ab 长度相同,定义为可扩张;
  • ab 长度不同,根据「ab 长度对比」以及「a 的长度大小」分情况讨论:
    • b 长度大于 a,不可扩张;
    • a 长度大于 b我们不一定要拿整一段的 b 进行扩张,可以拿 b 中的一个字符进行扩张。 因此只需要满足扩张后的长度(a 的长度)大于等于 33 即可定义为可扩张。

搞明白何为 “扩张” 后,剩余的则是简单的「双指针 + 模拟」做法。

Java 代码:

class Solution {
    public int expressiveWords(String s, String[] words) {
        int n = s.length(), ans = 0;
        out:for (String word : words) {
            int m = word.length(), i = 0, j = 0;
            while (i < n && j < m) {
                if (s.charAt(i) != word.charAt(j)) continue out;
                int a = i, b = j;
                while (a < n && s.charAt(a) == s.charAt(i)) a++;
                while (b < m && word.charAt(b) == word.charAt(j)) b++;
                a -= i; b -= j;
                if (a != b && (b > a || a < 3)) continue out;                
                i += a; j += b;
            }
            if (i == n && j == m) ans++;
        }
        return ans;
    }
}

C++ 代码:

class Solution {
public:
    int expressiveWords(string s, vector<string>& words) {
        int n = s.size(), ans = 0;
        for (const string &word : words) {
            int m = word.size(), i = 0, j = 0;
            while (i < n && j < m) {
                if (s[i] != word[j]) break;
                int a = i, b = j;
                while (a < n && s[a] == s[i]) a++;
                while (b < m && word[b] == word[j]) b++;
                a -= i; b -= j;
                if (a != b && (b > a || a < 3)) break;                
                i += a; j += b;
                if (i == n && j == m) ans++;
            }
        }
        return ans;
    }
};

Python 代码:

class Solution:
    def expressiveWords(self, s: str, words: List[str]) -> int:
        n, ans = len(s), 0
        for word in words:
            m, i, j = len(word), 0, 0
            ok = True
            while ok and i < n and j < m:
                if s[i] != word[j]:
                    ok = False
                a, b = i, j
                while a < n and s[a] == s[i]:
                    a += 1
                while b < m and word[b] == word[j]:
                    b += 1
                a, b = a - i, b - j
                if a != b and (b > a or a < 3):
                    ok = False
                i, j = i + a, j + b
            if ok and i == n and j == m:
                ans += 1
        return ans

TypeScript 代码:

function expressiveWords(s: string, words: string[]): number {
    let n = s.length, ans = 0
    out:for (const word of words) {
        let m = word.length, i = 0, j = 0
        while (i < n && j < m) {
            if (s[i] != word[j]) continue out
            let a = i, b = j
            while (a < n && s[a] == s[i]) a++
            while (b < m && word[b] == word[j]) b++
            a -= i; b -= j;
            if (a != b && (b > a || a < 3)) continue out
            i += a; j += b;
        }
        if (i == n && j == m) ans++;
    }
    return ans
}
  • 时间复杂度:O(n×m+i=0m1words[i].length)O(n \times m + \sum_{i = 0}^{m - 1}words[i].length),其中 n 为字符串 s 的长度,m 为数组 words 的长度
  • 空间复杂度:O(1)O(1)

最后

给大伙通知一下 📢 :

全网最低价 LeetCode 会员目前仍可用!!!

📅 年度会员:有效期加赠两个月!!; 季度会员:有效期加赠两周!!

🧧 年度会员:获 66.66 现金红包!!; 季度会员:获 22.22 现金红包!!

🎁 年度会员:参与当月丰厚专属实物抽奖(中奖率 > 30%)!!

专属链接:leetcode.cn/premium/?promoChannel=acoier

我是宫水三叶,每天都会分享算法知识,并和大家聊聊近期的所见所闻。

欢迎关注,明天见。

更多更全更热门的「笔试/面试」相关资料可访问排版精美的 合集新基地 🎉🎉