这段代码的大O是什么?我知道所有的行都是O(1),除了递归部分.我不确定递归的大O是什么,我感觉它仍然是O(1),因为我们没有比O(1)差的行,但通常递归是O(n).
码:
public int getSum(int a, int b) {
if (b == 0){
return a;
}
if (a == 0){
return b;
}
int add = a ^ b;
int carry = (a&b) << 1;
return getSum(add, carry);
}
Run Code Online (Sandbox Code Playgroud)
编辑:顺便说一下,这不是作业,而是为面试做好准备.
我如何获得标签内的标签?
这里的 td 标签如下:
<td scope="row"><a href="/Archives/edgar/data/1085621/000108562117000004/actuacorp12312016.htm">actuacorp12312016.htm</a></td>
Run Code Online (Sandbox Code Playgroud)
我想要其中的 href 标记的值,主要是 htm 链接:
<a href="/Archives/edgar/data/1085621/000108562117000004/actuacorp12312016.htm">actuacorp12312016.htm</a>
Run Code Online (Sandbox Code Playgroud)
我有这样的标签:
<tr>
<td scope="row">1</td>
<td scope="row">10-K</td>
<td scope="row"><a href="/Archives/edgar/data/1085621/000108562117000004/actuacorp12312016.htm">actuacorp12312016.htm</a></td>
<td scope="row">10-K</td>
<td scope="row">2724989</td>
</tr>
<tr class="blueRow">
<td scope="row">2</td>
<td scope="row">EXHIBIT 21.1</td>
<td scope="row"><a href="/Archives/edgar/data/1085621/000108562117000004/exhibit211q42016.htm">exhibit211q42016.htm</a></td>
<td scope="row">EX-21.1</td>
<td scope="row">21455</td>
</tr>
<tr>
<td scope="row">3</td>
<td scope="row">EXHIBIT 23.1</td>
<td scope="row"><a href="/Archives/edgar/data/1085621/000108562117000004/exhibit231q42016.htm">exhibit231q42016.htm</a></td>
<td scope="row">EX-23.1</td>
<td scope="row">4354</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
查看所有标签的代码:
base_url = "https://www.sec.gov/Archives/edgar/data/1085621/000108562117000004/" \
"0001085621-17-000004-index.htm"
response = requests.get(base_url)
base_data = response.content
base_soup = BeautifulSoup(base_data, "html.parser")
Run Code Online (Sandbox Code Playgroud) del my_list [:]的大O是什么?此命令删除列表中的所有元素.我的理解是它将是O(n).n是列表的长度.
因此,这段代码的大O将是bigO(n ^ 2),对吗?
请注意,这不是针对学校的,而是针对我在面试时练习的理解.
from copy import deepcopy
class Solution:
# @param A : list of integers
# @return an integer
def removeDuplicates(self, A):
copy_array = deepcopy(A)
del A[:]
for j in copy_array:
if j in A:
pass
else:
A.append(j)
return len(A)
Run Code Online (Sandbox Code Playgroud) 什么是位数的大 O?我不确定该方法是如何工作的,但我认为它是在 O(logn) 中完成的。
特别是使用此代码(其中 x = 4,y = 1):
return Integer.bitCount(x^y);
Run Code Online (Sandbox Code Playgroud) 我有这个标签:
<span class="companyName">Actua Corp <acronym title="Central Index Key">CIK</acronym>#: <a href="/cgi-bin/browse-edgar?action=getcompany&CIK=0001085621&owner=include&count=40">0001085621 (see all company filings)</a></span>
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得该值 <span class="companyName">.
在这种情况下,Actua公司
我对所有方法持开放态度.
我对java很陌生(我已经习惯了python)。
注意:即使调整图形用户界面的大小,我确实希望该位置保持在中心。
我想知道如何使单个按钮居中?目前,该按钮位于 GUI 的顶部。
public class main_gui extends JFrame{
public static void main(String[] args) {
// Initial window
JFrame start_frame = new JFrame("P.D");
start_frame.setSize(1200, 800);
start_frame.setVisible(true);
start_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Panel to hold our buttons
JPanel start_panel = new JPanel();
start_frame.add(start_panel);
// Button to initialize everything
JButton start_button = new JButton("Start");
// Take out the border around the text
start_button.setFocusable(false);
start_panel.add(start_button);
}
}
Run Code Online (Sandbox Code Playgroud)
这是当前的样子,我只想把这个按钮向下一点,放到中间。
假设我有一个包含多个字符串的列表.举个例子:
['dirty room', 'do to i', 'dormitory', 'dry to or i', 'i to rod', 'or to i dry', 'rod to i', 'room i dry', 'root i dry', 'to rod i']
Run Code Online (Sandbox Code Playgroud)
有没有办法删除或弹出字符串中有多个空格的所有项目?这样输出将是:
['dirty room', 'dormitory']
Run Code Online (Sandbox Code Playgroud) 我显然解决了一个非常简单的问题,即将字符串中的字符转换为小写tolower()。但是,我看到有人使用它,这是一个公认的解决方案。
这是tolower()cpp中功能的替代方法吗?如果是这样,为什么?
对问题的引用:https : //atcoder.jp/contests/abc126/tasks/abc126_a
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
// We want to convert "ABC" to "aBC"
string S = "ABC";
S[0] += 0x20;
// Returns "aBC"
cout << S << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)