摘要:題目鏈接除了用先處理之外,還可以用保存所有不含某個字母的,這么寫。
Maximum Product of Word Lengths
題目鏈接:
https://leetcode.com/problems...
public class Solution { public int maxProduct(String[] words) { // bit array to store the words // each word use bit represent: 1 << (c - "a") int n = words.length; int[] nums = new int[n]; for(int i = 0; i < n; i++) { for(int j = 0; j < words[i].length(); j++) { nums[i] = nums[i] | (1 << words[i].charAt(j) - "a"); } } // check & == 0 int max = 0; for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { if((nums[i] & nums[j]) == 0) max = Math.max(max, words[i].length() * words[j].length()); } } return max; } }
除了用bit先處理之外,還可以用set保存所有不含某個字母的word,python這么寫。參考這個博客:
http://bookshadow.com/weblog/...
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/66620.html
摘要:將低位的二進制數(shù)分別對應(yīng)字母,從而用二進制數(shù)實現(xiàn)一個簡單的。因此單詞對應(yīng)的二進制數(shù)為那么比較兩個單詞是否有重復(fù)的字母只需要將二者的二進制形式進行操作即可。 題目要求 Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do ...
摘要:本項目使用網(wǎng)絡(luò)上收集的對聯(lián)數(shù)據(jù)集地址作為訓(xùn)練數(shù)據(jù),運用注意力機制網(wǎng)絡(luò)完成了根據(jù)上聯(lián)對下聯(lián)的任務(wù)。這種方式在一定程度上降低了輸出對位置的敏感性。而機制正是為了彌補這一缺陷而設(shè)計的。該類中有兩個方法,分別在訓(xùn)練和預(yù)測時應(yīng)用。 桃符早易朱紅紙,楊柳輕搖翡翠群 ——FlyAI Couplets 體驗對對聯(lián)Demo: https://www.flyai.com/couplets s...
摘要:本項目使用網(wǎng)絡(luò)上收集的對聯(lián)數(shù)據(jù)集地址作為訓(xùn)練數(shù)據(jù),運用注意力機制網(wǎng)絡(luò)完成了根據(jù)上聯(lián)對下聯(lián)的任務(wù)。這種方式在一定程度上降低了輸出對位置的敏感性。而機制正是為了彌補這一缺陷而設(shè)計的。該類中有兩個方法,分別在訓(xùn)練和預(yù)測時應(yīng)用。 桃符早易朱紅紙,楊柳輕搖翡翠群 ——FlyAI Couplets 體驗對對聯(lián)Demo: https://www.flyai.com/couplets s...
閱讀 3170·2023-04-25 18:06
閱讀 3551·2021-11-22 09:34
閱讀 3038·2021-08-12 13:30
閱讀 2193·2019-08-30 15:44
閱讀 1821·2019-08-30 13:09
閱讀 1776·2019-08-30 12:45
閱讀 1861·2019-08-29 11:13
閱讀 3748·2019-08-28 17:51