jessonyue / leetcodelearning Goto Github PK
View Code? Open in Web Editor NEW这个仓库主要用于每天一题,大家的自发刷题,大家可以自由的提交和修改
License: MIT License
这个仓库主要用于每天一题,大家的自发刷题,大家可以自由的提交和修改
License: MIT License
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
if (headA == nullptr || headB == nullptr) {
return nullptr;
}
int lengthA = 1;
int lengthB = 1;
ListNode *a = headA;
ListNode *b = headB;
while (a->next != nullptr) {
lengthA++;
a = a->next;
}
while (b->next != nullptr) {
lengthB++;
b = b->next;
}
if (a != b) {
return nullptr;
}
int dx = abs(lengthA - lengthB);
a = headA;
b = headB;
if (lengthA > lengthB) {
while (dx--) {
a = a->next;
}
} else if (lengthA < lengthB) {
while (dx--) {
b = b->next;
}
}
while (a && b) {
if (a == b) {
return a;
}
a = a->next;
b = b->next;
}
return nullptr;
}
这个是c++的
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
if(headA == null || headB == null) {
return null;
}
//跑到最后一个节点,判断是否相同,统计长度
//相同则有,不同则无
//长的先跑这部分长度,然后一起跑等相等
ListNode p = headA, q = headB;
int lengthA = 1, lengthB = 1;
while (p.next != null) {
lengthA ++;
p = p.next;
}
while (q.next != null) {
lengthB ++;
q = q.next;
}
if(p == q) {
int length = Math.abs(lengthA - lengthB);
for (int i = 0; i < length; i ++) {
if(lengthA > lengthB) {
headA = headA.next;
}else {
headB = headB.next;
}
}
while (headA != null && headB != null) {
if(headA == headB) {
return headA;
}
headA = headA.next;
headB = headB.next;
}
}
return null;
}
读完全篇并没有明白有符号数到无符号数的隐式转化会造成什么问题?
读到这个问题时,感觉解释的比较模糊,并且没有真正去提取造成的问题点,所以无法理解问题点在哪里, 而后面解释又很模糊,感觉完全没有理解到转化后问题再在哪里?
看完这两个例子 和后面的解释 还是没有感觉到文中所说的细微的差距在哪里?
#include
using namespace std;
int climbStairs(int n);
int main() {
cout << "Hello, World!" << endl;
int number = 15;
int value = climbStairs(number);
cout << "返回值为:"<< value << endl;
return 0;
}
int climbStairs(int n) {
if( n == 0 || n == 1 || n == 2){
return n;
}
int num[] = {1,2};
for (int i = 2; i < n; ++i) {
num[i] = num[i-1] + num[i-2];
cout << "当前值为:" << num[i] <<endl;
}
return num[n-1];
}
main函数中调用的 int value = climbStairs(number);没有返回值?
问题类型:链表、指针
问题:删除链表中指定的节点,操作完成后是否应该返回链表?
自我理解:返回不返回其实都一样,指针操作的都是传进来的这个链表。代码如下:
//删除指定的节点
void deleteNode(LinkedList_* list,Node_* node){
Node_* cur = list->head;
while(cur->next!=NULL)
{
cur = cur->next;
if(cur->next->data == node->data)
{
break;
}
}
Node_* del = cur->next;
Node_* aft = del->next;
cur->next = aft;
list->length -=1;
}
疑惑:不知道是不是这样理解的,还是涉及编码规范应该写返回值?(添加同理)望路哥指点。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.