303. Range Sum Query - Immutable303. Range Sum Query - Immutable
DescriptionGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:Given nums = [-2, 0, 3, -5, 2, -1]
sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3Note:
Yo...
655. Print Binary TreeLeetCode. 655.Print Binary Tree
DescriptionPrint a binary tree in an m*n 2D string array following these rules:
The row number m should be equal to the height of the given binary tree.The column number n should always be an odd number.The root node’s value (in string format)...
561. Array Partition ILeetCode 561
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.
Example 1:
Input: [1,4,3,2]
Output: 4Explanation: n is 2, ...
566. Reshape the MatrixIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.
You’re given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number...
174. Dungeon GameThe demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescu...
404. Sum of Left Leaves 左叶子结点值之和Find the sum of all left leaves in a given binary tree.
Example:3
/ \ 9 20 / \ 15 7
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
Resolution12345678910111213141516171819202122/** * C++ * Definition for a bi...
455. Assign Cookies 饼干🍪分配Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s...
461. Hamming Distance 汉明距离The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Note:0 ≤ x, y < 231.
Example:Input: x = 1, y = 4
Output: 2
Explanation:1 (0 0 0 1)4 (0 1...
Judge Route Circle 机器人是否返回原点Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.
The move sequence is represented by a string. And each move is represent by a character. The valid robot ...
Two Sum 两数之和Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the sameelement twice.
Example:1234Given nums = [2, 7, 11, 15], target = 9,Because nu...
Python 错误处理try 来运行代码,如果执行出错,则后续代码不会继续执行,而是直接跳转至错误处理代码,即 except 语句块,执行完 except 后,如果有 finally 语句块,则执行。
finally 如果有,则一定会被执行(finally 语句可以不设)
可以设多个 except 来捕获不同类型的错误
1234567891011try: print('try...') r = 10 / int('a') print('result:', r)except ValueError as e: print('ValueError:', e)except...
Python_Advanced_Function_Programming通过大段代码拆成函数,通过一层一层的函数调用,可以把复杂的任务分解成简单的任务,这种分解可以称之为面向过程的程序设计。函数就是面向过程的程序设计的基本单元。
函数式编程,可以归结到面向过程的程序设计,但其思想更接近数学计算。
越低级的语言,越接近计算机,抽象程度低,执行效率高,如 C 语言;越高级的语言,越接近计算,抽象程度高,执行效率低,如 Lisp 语言。
纯函数式编程:
函数没有变量,因此,任意一个函数,只要输入是确定的,输出就是确定的,这种纯函数称之为没有副作用
非纯函数式编程:
允许使用变量的程序设计...
图的概念图 G 由顶点集 V 和边集 E 组成,记为 G=(V, E),其中 V(G) 表示图 G 中顶点的有限非集;E(G) 表示图 G 中顶点之间的关系(边)的集合。
注意:图不可以是空图,也就是说图中不能一个顶点都没有,但是边集可以为空
有向图边 E 是有向边的有限集合。入度和出度分别等于边数
无向图边 E 是无向边的有限集合。无向图的度之和为边数的两倍
简单图
不存在重复的边
不存在顶点到自身的边
多重图图 G 中某两个结点之间的边数多余一条,又允许顶点通过同一条边和自己关联。多重图的定义与简单图相对。
完全图(简单完全图)
无向完全图:在无向图中,任意两个顶点之间都存在边。含...
爬取京东《刻意练习》图书评论并生成图词前言:
本文主要为爬虫入门篇,通过简单的 requests 模块,爬取京东销售的图书《刻意练习》的评论,并生成云图词,体验爬虫的小乐趣。
实现的目的《刻意练习》这本书是一本非常棒的书,作者通过长时间的观察和亲身实践,研究和讲述学习的过程,以及从新手到大师 master 的必经之路,和刻意练习之方法。
如果非常喜欢这本书,想看一下买这本书的人对于这本书的评价是什么样的,当然可以自己去看评论区,但是只能草略的看,想全面的评论统计,那么就需要爬虫出马了。
通过爬虫可以快速地,大量地爬取到有关这本图书的几乎所有的评论,然后统计所有评论中的关键词,生成词图...
物联网新型智慧城市的发展智慧城市的概念及普及 智慧城市是一个对未来美好城市构建的梦想,在创新的物联网技术概念的推动之下,智慧城市的发展会有一个更加快速和稳定的推动。同样,随着 5G 技术的普及,物联网型新型智慧城市也将会迎来一个前所未有的发展新动力, 5G 的应用将会打破物联网发展的技术瓶颈,5G 的高性能、高频段、超宽带承载网络、超低延时、超高速等技术优势将推动物联网的应用成熟,而物联网的快速成熟应用推动城市技术的成为主流,推动城市化的智慧型快速发展。
什么是智慧城市 智慧城市(Smart City)是指利用各种信息技术或者创新意念,主要由信息和通信技术...
树与二叉树树(上)引子查找:根据某个给定关键字 K,从集合 R 中找出关键字与 K 相同的记录
静态查找:集合中记录是固定的。没有插入和删除操作,只有查找
顺序查找:(通过设置哨兵,进行判断是否找到元素或者是否到达表末尾)
123456789101112int SequentialSearch(list Tbl, ElementType k){ int i; Tb1->Element[0] = k; //建立哨兵,最后函数返回的时候如果值为0,则没找到 for(i = Tab->Length; Tb1->Element[i]!=k; i--); r...