Giter Club home page Giter Club logo

leetcodelearning's People

Contributors

997262600 avatar andyaplah avatar austenyad avatar bloodbamboo avatar caoguzhang avatar cjlsuper avatar crashtestgithub avatar cwxvashon avatar empty56631 avatar fanwuye avatar feature211 avatar foryoung2016 avatar geesonlin888 avatar ghryujin avatar guangzq avatar haowangcold avatar itzuo avatar jessonyue avatar lanfairy avatar qianchunzheng avatar singlerzhou avatar sinlazhan avatar slowhandwc avatar vxos avatar wadeqing avatar whoislxy avatar world4ugit avatar xiaoxixigh avatar xt4665699 avatar zpjsmalltime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leetcodelearning's Issues

2020.06.5 面试题 02.07. 链表相交

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;

    }

这个是java的
cpp_java对比
发现运行时间差距很大

路哥 读书中我产生了一个问题

读完全篇并没有明白有符号数到无符号数的隐式转化会造成什么问题?

读到这个问题时,感觉解释的比较模糊,并且没有真正去提取造成的问题点,所以无法理解问题点在哪里, 而后面解释又很模糊,感觉完全没有理解到转化后问题再在哪里?

看完这两个例子 和后面的解释 还是没有感觉到文中所说的细微的差距在哪里?

爬楼梯算法-c++语法问题

#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;
}

疑惑:不知道是不是这样理解的,还是涉及编码规范应该写返回值?(添加同理)望路哥指点。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.