leetcode哈希表(python与c++)

1.整数转罗马数字

python:

class Solution:def intToRoman(self, num: int) -> str:dict_ = {1000:'M', 900:'CM', 500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9:'IX', 5:'V', 4:'IV', 1:'I'}res = ''for key in dict_:count = num // keyres += count * dict_[key]num %= keyreturn res

c++: 

class Solution {
public:string intToRoman(int num) {int value[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};string str_[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};string res;for(int i = 0; i < 13; i++){while(num >= value[i]){num -= value[i];res += str_[i];}}return res;}
};

2.电话号码的字母组合 

 python:

class Solution:def help(self, digits, track):if len(digits)==0:self.res.append(''.join(track))returnfor letter in self.dict_[digits[0]]:# store = track.copy()track.append(letter)self.help(digits[1:], track)# track.pop()track = storedef letterCombinations(self, digits: str) -> List[str]:if len(digits)==0:return []self.dict_={"2":"abc","3":"def","4":"ghi","5":"jkl","6":"mno","7":"pqrs","8":"tuv","9":"wxyz"}self.res = []self.help(digits, [])return self.res

c++:

class Solution {
public:vector<string> res;// unordered_map<char, string> phoneMap;void help(string digits, vector<char> track, unordered_map<char, string> phoneMap){if(digits.empty()){string str(track.begin(), track.end());res.push_back(str);}for(int i=0; i < phoneMap[digits[0]].size(); i++){track.push_back(phoneMap[digits[0]][i]);help(digits.substr(1, digits.size() - 1), track, phoneMap);track.pop_back();}}vector<string> letterCombinations(string digits) {if (digits.empty()) {return res;}unordered_map<char, string> phoneMap{{'2', "abc"},{'3', "def"},{'4', "ghi"},{'5', "jkl"},{'6', "mno"},{'7', "pqrs"},{'8', "tuv"},{'9', "wxyz"}};vector<char> track;help(digits, track, phoneMap);return res;}
};

3.有效的数独

思路用三个hash 记录即可

python:

class Solution:def isValidSudoku(self, board: List[List[str]]) -> bool:rows = [{i:0} for i in range(9)]# print(rows)cols = [{i:0} for i in range(9)]boxs = [{i:0} for i in range(9)]for i in range(9):for j in range(9):box_index = (i // 3) * 3 + j // 3if board[i][j] != '.':num = int(board[i][j])rows[i][num] = rows[i].get(num, 0) + 1cols[j][num] = cols[j].get(num, 0) + 1 boxs[box_index][num] = boxs[box_index].get(num, 0) + 1# print(rows)# print('==i', i)# print('==num', num)if rows[i][num] > 1 or cols[j][num] > 1 or boxs[box_index][num] > 1:    return Falsereturn True

c++: 

class Solution {
public:bool isValidSudoku(vector<vector<char>>& board) {vector<vector<int>> rows(9, vector<int>(9, 0));vector<vector<int>> cols(9, vector<int>(9, 0));vector<vector<int>> boxs(9, vector<int>(9, 0));for(int i = 0; i < 9; i++){for(int j = 0; j < 9; j++){if (board[i][j] == '.') continue;int num = board[i][j] - '1';int box_index = (i / 3) * 3 + j / 3;rows[i][num]++;cols[j][num]++;boxs[box_index][num]++;if(rows[i][num] > 1 || cols[j][num] > 1 || boxs[box_index][num] > 1){return false;}}}return true;}
};

4.字母异位词分组

python:

class Solution:def groupAnagrams(self, strs: List[str]) -> List[List[str]]:dict_={}for i in range(len(strs)):str_ = ''.join(sorted(strs[i]))if str_ in dict_:dict_[str_].append(strs[i])else:dict_[str_] = [strs[i]]# print(dict_.values())return list(dict_.values())

c++:

class Solution {
public:vector<vector<string>> groupAnagrams(vector<string>& strs) {vector<vector<string>> result;map<string, vector<string>> dict_; for(int i = 0; i < strs.size(); i++){string s = strs[i];sort(s.begin(), s.end());dict_[s].push_back(strs[i]);}map<string, vector<string>> ::iterator it;for(it = dict_.begin(); it != dict_.end(); it++){result.push_back(it->second);}// for(auto x:dict_){ //     result.push_back(x.second);// }return result;}
};

5.矩阵置零

python:

class Solution:def setZeroes(self, matrix: List[List[int]]) -> None:"""Do not return anything, modify matrix in-place instead."""m, n = len(matrix), len(matrix[0])row, col = [False] * m, [False] * nfor i in range(m):for j in range(n):if matrix[i][j] == 0:row[i] = col[j] = Truefor i in range(m):for j in range(n):if row[i] or col[j]:matrix[i][j] = 0

c++: 

class Solution {
public:void setZeroes(vector<vector<int>>& matrix) {int m = matrix.size();int n = matrix[0].size();vector<int> row(m, 0), col(n, 0);for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (!matrix[i][j]) {row[i] = col[j] = 1;}}}for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (row[i] || col[j]) {matrix[i][j] = 0;}}}}
};

6.最小覆盖子串

思路:滑动窗口

python:

class Solution:def minWindow(self, s: str, t: str) -> str:dict_ = {}for i in t:dict_[i] = dict_.get(i, 0)+1# print('dict_:', dict_)n = len(s)left, right = 0,0remain = 0res = ''minlen = float('inf')while right < n:#向右边拓展if s[right] in dict_:if dict_[s[right]]>0:#大于0这个时候加才有效否则是重复字符remain+=1dict_[s[right]]-=1while remain == len(t):#left 要拓展了 也就是左边要压缩if (right - left) < minlen:minlen = right-leftres = s[left:right+1]# print('==res:', res)left+=1if s[left-1] in dict_:#注意这里left已经加1了 要用前一个字符也就是s[left-1]dict_[s[left - 1]] += 1if dict_[s[left-1]]>0:#大于0这个时候减去才有效否则是重复字符remain -= 1right += 1#放后面进行向右拓展# print('==res:', res)return res

7.单词接龙 II

思路:构建图 然后bfs

python:

class Solution:def findLadders(self, beginWord: str, endWord: str, wordList: List[str]) -> List[List[str]]:cost = {}for word in wordList:cost[word] = float("inf")cost[beginWord] = 0# print('==cost:', cost)# neighbors = collections.defaultdict(list)neighbors = {}ans = []#构建图for word in wordList:for i in range(len(word)):key = word[:i] + "*" + word[i + 1:]if key not in neighbors:neighbors[key] = []neighbors[key].append(word)else:neighbors[key].append(word)# print('==neighbors:', neighbors)q = [[beginWord]]# print('====q:', q)#bfswhile q:path = q.pop(0)# print('===path:', path)cur = path[-1]if cur == endWord:ans.append(path.copy())else:for i in range(len(cur)):new_key = cur[:i] + "*" + cur[i + 1:]if new_key not in neighbors:continuefor neighbor in neighbors[new_key]:# print('==cost[cur] + 1, cost[neighbor]:', cost[cur] + 1, cost[neighbor])if cost[cur] + 1 <= cost[neighbor]:q.append(path + [neighbor])cost[neighbor] = cost[cur] + 1# print('==ans:', ans)# print(cost)return ans

8.最长连续序列

python:

class Solution:def longestConsecutive(self, nums: List[int]) -> int:temp = 1long_length = 0nums = set(nums)for num in nums:if num - 1 in nums:continuewhile num + 1 in nums:temp += 1num += 1long_length = max(long_length, temp)temp = 1return long_length

c++: 

class Solution {
public:int longestConsecutive(vector<int>& nums) {unordered_set<int> unums;for(int num:nums){unums.insert(num);}int LongLength = 0, temp = 1;for(int num: unums){if(unums.count(num - 1)){continue;}while(unums.count(num + 1)){temp++;num++;                }LongLength = max(LongLength, temp);temp = 1;}return LongLength;}
};

9-1. 单词拆分

思路1:动态规划

#动态规划 dp[i]表示 s 的前 i 位是否可以用 wordDict 中的单词表示,
#
class Solution:def wordBreak(self, s, wordDict):n = len(s)dp = [False] * (n + 1)dp[0] = Truefor i in range(n):for j in range(i+1, n+1):if dp[i] and (s[i:j] in wordDict):dp[j] = Trueprint('==dp:', dp)return dp[-1]
s = "leetcode"
wordDict = ["leet", "code"]
sol = Solution()
res=  sol.wordBreak(s, wordDict)
print('==res:', res)

c++实现:

class Solution {
public:bool wordBreak(string s, vector<string>& wordDict) {int n = s.size();unordered_set<string> wordDictSet;for (auto word: wordDict) {wordDictSet.insert(word);}        vector<bool> dp(n+1, false);dp[0] = true;for(int i = 0; i < n; i++){for(int j = i+1; j < n+1; j++){                if(dp[i] && wordDictSet.find(s.substr(i, j - i)) != wordDictSet.end())                 {// cout<<"s.substr(i, j - i):"<<s.substr(i, j - i)<<endl;dp[j] = true;}}}return dp[n];}
};

思路2:回溯加缓存


#递归 lru_cache用于缓存 将数据缓存下来 加快后续的数据获取 相同参数调用时直接返回上一次的结果
import functools
class Solution:@functools.lru_cache()def helper(self, s):if len(s) == 0:return Trueres = Falsefor i in range(1, len(s)+1):if s[:i] in self.wordDict:res = self.helper(s[i:]) or resreturn resdef wordBreak(self, s, wordDict):self.wordDict  = wordDictreturn self.helper(s)
s = "leetcode"
wordDict = ["leet", "code"]
# s = "aaaaaaa"
# wordDict = ["aaaa", "aaa"]
# s= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
# wordDict = ["a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaa","aaaaaaaa","aaaaaaaaa","aaaaaaaaaa"]
sol = Solution()
res=  sol.wordBreak(s, wordDict)
print('==res:', res)

9-2.单词拆分 II

思路:递归 


class Solution:def helper(self, s, wordDict, memo):if s in memo:#递归终止条件return memo[s]if s=='':#递归终止条件return []res = []for word in wordDict:if not s.startswith(word):continueif len(word)==len(s):#匹配上刚好相等res.append(word)else:#匹配上 但是字符还没到最后rest = self.helper(s[len(word):], wordDict, memo)for tmp in rest:tmp = word+ " "+ tmpres.append(tmp)print('==res:', res)print('==memo:', memo)memo[s] = resreturn resdef wordBreak(self, s, wordDict):if s=='':return []return self.helper(s, wordDict, memo={})
s = "catsanddog"
wordDict = ["and", "cat", "cats", "sand", "dog"]
# s = "cat"
# wordDict = ["cat"]
sol = Solution()
res = sol.wordBreak(s, wordDict)
print(res)

c++:

class Solution {
public:vector<string> helper(string s, vector<string>& wordDict){vector<string> res;for(int i = 0; i < wordDict.size(); i++){string word = wordDict[i];if(s.find(word) != 0){continue;}if(word == s){res.push_back(word);}else{vector<string> temp;temp = helper(s.substr(word.size(), s.size()), wordDict);for(string temp_:temp){res.push_back(word + " "+temp_);}}            }return res;}vector<string> wordBreak(string s, vector<string>& wordDict) {if (s.size()==0){return {};}return helper(s, wordDict);}
};

10-1.环形链表

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = Noneclass Solution:def hasCycle(self, head: ListNode) -> bool:#快慢指针 人追人slow,fast = head,headwhile fast and fast.next:fast = fast.next.nextslow = slow.nextif slow==fast:return True            return False

c++实现:

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode(int x) : val(x), next(NULL) {}* };*/
class Solution {
public:bool hasCycle(ListNode *head) {ListNode* slow = head;ListNode* fast = head;while(fast && fast->next){slow = slow->next;fast = fast->next->next;if(slow == fast){return true;}}return false;}
};

10-2.给定一个有环链表,实现一个算法返回环路的开头节点。

假设有两个指针,分别为快慢指针fast和slow, 快指针每次走两步,慢指针每次前进一步,如果有环则两个指针必定相遇;

反证法:假设快指针真的 越过 了慢指针,且快指针处于位置 i+1,而慢指针处于位置 i,那么在前一步,快指针处于位置 i-1,慢指针也处于位置 i-1,它们相遇了。

A:链表起点
B:环起点
C:相遇点
X:环起点到相遇点距离
Y:链表起点到环起点距离
R:环的长度
S:第一次相遇时走过的路程

1.慢指针slow第一次相遇走过的路程 S1 = Y + X;(11)
快指针fast第一次相遇走过的路程 S2=2S1 = Y + X + NR;(2)
说明:快指针的速度是慢指针的两倍,相同时间内路程应该是慢指针的两倍,Y + X + NR是因为快指针可能经过N圈后两者才相遇;
把(1)式代入(2)式得:Y = NR -X; 

2..在将慢指针回到A点,满指针和快指针同时走,在B点相遇,此处就是环节点.

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = Noneclass Solution:def detectCycle(self, head: ListNode) -> ListNode:slow = headfast = head;while fast:if fast and fast.next:slow = slow.nextfast = fast.next.nextelse:return Noneif slow==fast:breakif fast ==None or fast.next==None:return Noneslow= headwhile slow!=fast:slow = slow.nextfast = fast.nextreturn slow

c++实现:

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode(int x) : val(x), next(NULL) {}* };*/
class Solution {
public:ListNode *detectCycle(ListNode *head) {ListNode* slow = head;ListNode* fast = head;while(fast){if(fast && fast->next){slow = slow->next;fast = fast->next->next;}else{return NULL;}if(slow==fast){break;}}if(!fast || !fast->next){return NULL;}slow = head;while(slow!=fast){slow = slow->next;fast = fast->next;}return slow;}
};

11. 重复的DNA序列

python: 

class Solution:def findRepeatedDnaSequences(self, s: str) -> List[str]:length = 10res = list()temp = dict()for i in range(len(s) - length + 1):temp[s[i:i+length]] = temp.get(s[i:i+length], 0) + 1if temp[s[i:i+length]] == 2:res.append(s[i:i+length])return res

c++: 

class Solution {
public:vector<string> findRepeatedDnaSequences(string s) {if(s.size() < 10){return {};}            vector<string> res;map<string, int> temp;int length=10;for(size_t i = 0; i < s.size() - length + 1; i++){string str_ = s.substr(i, length);temp[str_]++;// cout<<str_<<endl;// cout<<temp[str_]<<endl;if(temp[str_] == 2){res.push_back(str_);}}return res;}
};

12.快乐数

python:

class Solution:def nextN(self, n):sum_ = 0while n > 0:digit = n % 10n = n//10sum_ += digit**2return sum_def isHappy(self, n: int) -> bool:visit = set()while n!=1 and n not in visit:visit.add(n)n = self.nextN(n)return n==1

 c++

class Solution {
public:int nextN(int n){int sum_ = 0;while(n > 0){sum_ += (n % 10) * (n % 10);n /= 10;            }return sum_;}bool isHappy(int n) {unordered_set<int> visit;while(n != 1 && visit.find(n) == visit.end()){visit.insert(n);n = nextN(n);}// cout<<n;return n == 1;}
};

 13.同构字符串 

 python:

class Solution:def isIsomorphic(self, s: str, t: str) -> bool:if len(s) != len(t):return Falsedict_ = dict()for i in range(len(s)):if s[i] in dict_:if dict_[s[i]] != t[i]:return Falseelse:if t[i] in dict_.values():return Falsedict_[s[i]] = t[i]return True
class Solution:def isIsomorphic(self, s: str, t: str) -> bool:if len(s) != len(t):return Falsedict_1 = dict()dict_2 = dict()for i in range(len(s)):if (s[i] in dict_1 and dict_1[s[i]] != t[i]) or (t[i] in dict_2 and dict_2[t[i]] != s[i]): return Falsedict_1[s[i]] = t[i]dict_2[t[i]] = s[i]return True

c++:

class Solution {
public:bool isIsomorphic(string s, string t) {map<char, char> s2t;map<char, char> t2s;for (int i = 0; i < s.size(); ++i) {char x = s[i], y = t[i];if ((s2t.count(x) && s2t[x] != y) || (t2s.count(y) && t2s[y] != x)) {return false;}s2t[x] = y;t2s[y] = x;}return true;}
};

14.求众数 II

python:

class Solution:def majorityElement(self, nums: List[int]) -> List[int]:length = len(nums) // 3 + 1dict_ = {}for num in nums:dict_[num] = dict_.get(num, 0) + 1res = []for key in dict_:if dict_[key] >= length:res.append(key)return res

 c++:

class Solution {
public:vector<int> majorityElement(vector<int>& nums) {map<int, int> dict_;vector<int> res;int length = nums.size()/3 + 1;for(int &num:nums){dict_[num]++;}for(auto &iter:dict_){if(iter.second >= length){res.push_back(iter.first);}}return res;}
};

15.丑数 II

 python:

class Solution:def nthUglyNumber(self, n: int) -> int:dp = [1]*nindex_two = 0index_three = 0index_five = 0for i in range(1, n):two = dp[index_two]*2three = dp[index_three]*3five = dp[index_five]*5dp[i] = min(two, three, five)if dp[i] == two:index_two += 1if dp[i] == three:index_three += 1if dp[i] == five:index_five += 1# print(dp)return dp[-1]

c++:

class Solution {
public:int nthUglyNumber(int n) {vector<int>dp(n, 1);int index_two = 0, index_three = 0, index_five = 0;for(int i = 1; i < n; i++){int two = dp[index_two]*2;int three = dp[index_three]*3;int five = dp[index_five]*5;dp[i] = min(min(three, two), five);if(two == dp[i]){index_two++;}if(three == dp[i]){index_three++;}if(five == dp[i]){index_five++;}}return dp[n-1];}
};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/493063.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Yann LeCun、吴恩达的新年AI预测:强调“少样本学习”,AI恐慌在减少

来源&#xff1a;大数据文摘新年伊始&#xff0c;海外媒体VentureBeat电话访谈了包括吴恩达、Yann Lecun在内的四位人工智能领域领军者&#xff0c;询问了他们对于过去一年人工智能领域发展的看法&#xff0c;以及他们认为新一年人工智能和机器学习可能产生的突破。不约而同&am…

1.C#WinForm基础制作简单计算器

利用c#语言编写简单计算器&#xff1a; 核心知识点&#xff1a; MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//下拉序号MessageBox.Show(Convert.ToString(comboBox1.SelectedItem));//下拉内容MessageBox.Show(Convert.ToString(comboBox1.SelectedText));/…

seaborn的一些画图

一.数据查看 数据集地址,用红白酒为例&#xff0e; import pandas as pd import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import matplotlib as mpl import numpy as np import seaborn as snswhite_wine pd.read_csv(winequality-white.csv, se…

后摩尔定律时代的芯片新选择!

来源&#xff1a;gizmodo摘要&#xff1a;很长一段时间以来&#xff0c;摩尔定律和它的最终结局一直就像房间里的大象&#xff0c;不容忽视。英特尔联合创始人戈登摩尔在1965年的一篇论文中预测&#xff0c;芯片中的晶体管数量每年将翻一番。更多的晶体管意味着更快的速度&…

MSE和Cross-entropy梯度更新比较

一.平方损失(MSE) Loss函数: 梯度: 由于x,y是已知的&#xff0c;故可以忽略掉 梯度更新: sigmoid函数: 可以看出 导数在z取大部分值&#xff0c;都是很小的&#xff0c;这样会使梯度更新慢&#xff0e; y为1或0是&#xff0c;当a1,w的梯度为0,a0,w的梯度为0&#xff0c;故就…

麦卡锡问答:什么是人工智能?

来源&#xff1a;科学网一、基本问题问&#xff1a;什么是人工智能&#xff1f;答&#xff1a;人工智能是研制智能机器尤其是智能计算机程序的科学与工程。它与使用计算机理解人类智能类似&#xff0c;但人工智能并不将它自己局限于生物意义上的方法。问&#xff1a;是的&#…

操作系统--多进程管理CPU

一.cpu管理直观做法 最只管想法cpu循环取址执行&#xff0c;所以只需要设好pc初值即可 存在问题:io会占用时间长&#xff0c;导致cpu利用率低. 所以需要不停切换&#xff0c;执行多个程序&#xff0c;也就是并发&#xff0e; 但是在切换的时候&#xff0c;除了记录返回地址&a…

胶囊网络、边缘计算:2018年13个最新人工智能发展趋势

来源&#xff1a;亿欧智库摘要&#xff1a; 美国知名研究机构CB Insights的报告《2018年必看的人工智能热门趋势》&#xff0c;对AI行业发展现状进行了深入研究剖析&#xff0c;并给出了2018年AI领域最值得关注的13个前沿发展趋势。趋势一&#xff1a;新蓝领的工作——机器人保…

清空输入缓冲区fflush()

转自&#xff1a;http://blog.csdn.net/21aspnet/article/details/174326 scanf( )函数可以接收输入的换行符&#xff0c;\n,(asci为10)&#xff0c;利用函数fflush(stdin),可以清空输入内存缓冲区。 // function name fflush // 清空一个流 ,2014--03--29 #include <std…

操作系统--用户级线程与内核级线程

一.多进程是操作系统基本图像 进程都是在内核进行 二.用户级线程 2.1线程引入 可以切指令不切表&#xff0c;也就是资源不动&#xff0c;指令执行分开&#xff0c;更加轻量化&#xff0c;从而提高效率&#xff0c;保留并发优点&#xff0c;避免进程切换代价&#xff0c;也就…

“新视野”和“最远点”的约会

NASA 设想的2014 MU69 太空岩石 来源&#xff1a;中国科学报当新年香槟将陌生人聚在一起时&#xff0c;一种不同的聚会正在外太阳系进行。在距地球近65亿公里的地方&#xff0c;美国宇航局&#xff08;NASA&#xff09;“新视野”号探测器创下了寻访迄今最遥远世界的纪录。这场…

C语言里的写文件

转载自&#xff1a;http://blog.csdn.net/shuimuzhiyuan/article/details/6908335 部分转载自&#xff1a;http://blog.csdn.net/lijun5635/article/details/13095883 一 、fopen()函数中第一个形式参数表示文件名, 可以包含路径和文件名两部分。如: "B:TEST.DAT"…

操作系统--内核级线程实现

五段论 &#xff1a; 进入内核靠的是中断&#xff0c;fork是创建系统进程调用&#xff0c;进程由资源&#xff0b;执行序列组成&#xff0c;而创建执行序列其实就是创建线程&#xff0e; TSS:任务结构段 参考&#xff1a; 操作系统_哈尔滨工业大学_中国大学MOOC(慕课)…

一文看尽2018全年计算机视觉大突破

来源&#xff1a;极市平台摘要&#xff1a;计算机视觉领域同样精彩纷呈&#xff0c;与四年前相比GAN生成的假脸逼真到让人不敢相信&#xff1b;新工具、新框架的出现&#xff0c;也让这个领域的明天特别让人期待……2018&#xff0c;仍是AI领域激动人心的一年。计算机视觉领域同…

leetcode BFS(python+c++)

1.最小基因变化 思路&#xff1a;bfs搜索回溯 python: class Solution:def minMutation(self, start: str, end: str, bank: List[str]) -> int:library [A,C, G,T]queue [start]num 0vis set()while queue:size len(queue)for i in range(size):cur queue.pop(0)i…

北欧小国的宏大AI实验: 让1%的人口接受人工智能培训

编译&#xff1a; 机器之能 微胖摘要&#xff1a;芬兰希望在人工智能的实际应用方面占据一席之地&#xff0c;成为世界领先国家。2017 年 10 月&#xff0c;芬兰成为欧盟第一个将国家人工智能战略付诸实施的国家。在 2018 年 6 月发布的第二份报告中&#xff0c;政府估计&#…

形象理解矩阵操作

1.矩阵和向量线性变换 线性变换可看着是对空间的挤压伸展。 也就是看成把向量中的值对矩阵列向量加权 ,在对向量求和 2.矩阵和矩阵的线性变换 矩阵左乘就是对行向量操作&#xff0c;矩阵右乘就是对列向量操作&#xff0e; 可以将其中一个矩阵看成是多个列向量,在拆开对剩下矩…

CSAPP-计算机漫游

一.编译系统的工作流程: test.cpp #include <iostream> using namespace std; int main() { //hahha cout<<"hello world"<<endl; return 0; }直接生成可执行程序test g -o test test.cpp 深入解析生成可执行程序test的过程 1.g -E test.cpp &…

报告:下一代技术革命“AI”来袭

来源&#xff1a;199IT互联网数据中心摘要&#xff1a;Rolandberger发布了新报告“下一代技术革命‘AI’来袭”&#xff0c;分析了人们是否准备好迎接下一代技术革命。快进到2017年&#xff0c;我们正处于人工智能&#xff08;AI&#xff09;革命的风口浪尖。它会影响经济、工业…

CSAPP--信息的表示与处理

虚拟地址空间: 大多数 Intel 兼容机采用小端模式,IBM 和 Sun 公司的机器大多数机器采用大端法。 对于很多新的处理器,支持双端法,可以配置成大端或者小端运行。例如基于 ARM 架构的处理器,支持双端法,但是 Android 系统和 iOS 系统却只能运行在小端模式. 下面是代码测试,获取1…