成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[LintCode] Buy Fruits

邱勇 / 676人閱讀

Problem

Xiao Ming is going to help companies buy fruit. Give a codeList, which is loaded with the fruit he bought. Give a shoppingCart, which is loaded with target fruit. We need to check if the order in the codeList matches the order in the shoppingCart. Note that only the sum of the items in all linked lists in the codeList add up to less than or equal to the sum of items in the shoppingcart may return 1. In addition, the item in codeList may be "anything", which can match with any fruit.

Notice

The number of fruits in codeList and the number of fruits in shppingCart are both less than 2000.

Example

Given codeList = [["apple", "apple"],["orange", "banana", "orange"]],, shoppingCart = ["orange", "apple", "apple", "orange", "banana", "orange"], return 1.

Explanation:

Because the order in the codeList matches the fruit in the shoppingCart except for the first orange.

Given codeList = [["orange", "banana", "orange"],["apple", "apple"]], shoppingCart = ["orange", "apple", "apple", "orange", "banana", "orange"], return 0.

Explanation:

Because the order in the codeList doesn"t match the shoppingCart.

Given codeList = [["apple", "apple"],["orange", "anything", "orange"]], shoppingCart = ["orange", "apple", "apple", "orange", "mango", "orange"], return 1.

Explanation:

anything matches mango, so codeList can match the fruit of shoppingCart.
Solution
public class Solution {
    /**
     * @param codeList: The codeList
     * @param shoppingCart: The shoppingCart
     * @return: The answer
     */
    public int buyFruits(List> codeList, List shoppingCart) {
        // Write your code here
        List mingList = new ArrayList<>();
        for (List list: codeList) {
            for (String str: list) {
                mingList.add(str);
            }
        }
        
        if (mingList.size() > shoppingCart.size()) return 0;
        
        for (int i = 0; i <= shoppingCart.size()-mingList.size(); i++) {
            for (int j = 0; j < mingList.size(); j++) {
                String cur = mingList.get(j);
                if (cur.equals(shoppingCart.get(i+j)) || cur.equals("anything")) {
                    if (j == mingList.size()-1) return 1;
                    else continue;
                } else {
                    break;
                }
                
            }
        }
        
        return 0;
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/69441.html

相關(guān)文章

  • 傻瓜式學(xué)Python3——列表

    摘要:列表是編程中使用頻率極高的數(shù)據(jù)結(jié)構(gòu),由一系列按特定順序排列的元素組成,用表示,逗號(hào)分隔元素,類似中的數(shù)組。由于列表包含多個(gè)元素,所以通常命名為復(fù)數(shù)形式,如,等。使用切片裁剪獲取子列表使用列表名裁剪獲取對(duì)應(yīng)索引區(qū)間的子列。 前言: 好久不見,突然發(fā)覺好久沒寫博客了,最近迷上了 Python 無法自拔,了解了一下,Python 簡(jiǎn)單易學(xué),尤其是接觸過 java 的人,入門 Python 更...

    Andrman 評(píng)論0 收藏0
  • Python 數(shù)據(jù)科學(xué)基礎(chǔ)知識(shí)

    摘要:例如,和是非常著名的數(shù)據(jù)科學(xué)支持包。是用進(jìn)行科學(xué)計(jì)算的基礎(chǔ)包。意味著是維數(shù)組。下面的代碼得到二維數(shù)組的,返回的元組中的第一個(gè)元素是行數(shù),第二個(gè)元素是列數(shù)。 翻譯:瘋狂的技術(shù)宅原文:https://towardsdatascience.co... Python 數(shù)據(jù)類型 在 Python 中有許多數(shù)據(jù)類型。最常見的是float(浮點(diǎn)型),int(整型),str(字符串),bool(布爾...

    lwx12525 評(píng)論0 收藏0
  • 堅(jiān)持不懈續(xù)集 (二) 初學(xué)者挑戰(zhàn)學(xué)習(xí)Python編程30天

    摘要:元組是有序且不可更改或不可修改不可變的集合。不允許重復(fù)成員。列表是有序且可修改可變的不同數(shù)據(jù)類型的集合。避免上述問題的一種方法是使用。計(jì)數(shù)橙色年齡,,,,,,,打印年齡。語法反轉(zhuǎn)水果香蕉,橙色,芒果,檸檬水果。按字母順序排序,年齡。 ...

    Amio 評(píng)論0 收藏0
  • learning javascript - 數(shù)組

    摘要:過濾掉等于的數(shù)組元素返回一個(gè)新數(shù)組,數(shù)組中的元素為原始數(shù)組元素調(diào)用函數(shù)處理后的值數(shù)組元素平方用于檢測(cè)數(shù)組中的元素是否滿足指定條件如果有一個(gè)元素滿足條件,則表達(dá)式返回剩余的元素不會(huì)再執(zhí)行檢測(cè)如果沒有滿足條件的元素,則返回。 數(shù)組常用方法 創(chuàng)建數(shù)組 var fruits = [Apple, Banana]; console.log(fruits.length); 通過索引訪問數(shù)組元素 v...

    zzir 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<