NEW! Discover is now providing your FICO® Credit Score for free. View Now. 就在statement页面中间…… 这个是实时更新的么,或者多久更新一次?是真的FICO分数还是像CreditKarma那样的 模拟分啊? 而且根据FAQ,这个分数来自TU的……同样来自TU,creditkarma给我720,discover给 我770……这也差太多了……
/* add sibling pointer to the right sibling of each node in a tree, O(n) time, O(1) space. 5 minutes thinking, 10 minutes coding, a hint he gave me: recursion */ struct NODE { int nVal; NODE* pLft; NODE* pRgt; NODE* pSibling; NODE(int n) : nVal(n), pLft(NULL), pRgt(NULL), pSibling(NULL) {} }; void LinkRightFromParent(NODE* pNode, NODE* pParent) { if (pNode == NULL) return; //Under this situation, the current node will connect to the child of current parent if (pParent != NULL && pParent->pLft == pNode && pParent->pRgt != NULL) pNode->pSibling = pParent->pRgt; else //pitfall: when starting from parent chain search, should start at //the next node to the parent. E.g, if a parent got a left child and //right child, and the current node is right child, then the right child //will connect to the left child, then dead loop!!!! { NODE* pIter = pParent == NULL ? NULL : pParent->pSibling; //logic below is to find the next right node by parent chain NODE* pRgtCon = NULL; while (pIter != NULL && pRgtCon == NULL) { if (pIter->pLft != NULL) pRgtCon = pIter->pLft; else if (pIter->pRgt != NULL) pRgtCon = pIter->pRgt; pIter = pIter->pSibling; } pNode->pSibling = pRgtCon; } LinkRightFromParent(pNode->pRgt, pNode); LinkRightFromParent(pNode->pLft, pNode); }
【在 w****x 的大作中提到】 : /* : add sibling pointer to the right sibling of each node in a tree, O(n) time, : O(1) space. : 5 minutes thinking, 10 minutes coding, a hint he gave me: recursion : */ : struct NODE : { : int nVal; : NODE* pLft; : NODE* pRgt;
/* add sibling pointer to the right sibling of each node in a tree, O(n) time, O(1) space. 5 minutes thinking, 10 minutes coding, a hint he gave me: recursion */ struct NODE { int nVal; NODE* pLft; NODE* pRgt; NODE* pSibling; NODE(int n) : nVal(n), pLft(NULL), pRgt(NULL), pSibling(NULL) {} }; void LinkRightFromParent(NODE* pNode, NODE* pParent) { if (pNode == NULL) return; //Under this situation, the current node will connect to the child of current parent if (pParent != NULL && pParent->pLft == pNode && pParent->pRgt != NULL) pNode->pSibling = pParent->pRgt; else //pitfall: when starting from parent chain search, should start at //the next node to the parent. E.g, if a parent got a left child and //right child, and the current node is right child, then the right child //will connect to the left child, then dead loop!!!! { NODE* pIter = pParent == NULL ? NULL : pParent->pSibling; //logic below is to find the next right node by parent chain NODE* pRgtCon = NULL; while (pIter != NULL && pRgtCon == NULL) { if (pIter->pLft != NULL) pRgtCon = pIter->pLft; else if (pIter->pRgt != NULL) pRgtCon = pIter->pRgt; pIter = pIter->pSibling; } pNode->pSibling = pRgtCon; } LinkRightFromParent(pNode->pRgt, pNode); LinkRightFromParent(pNode->pLft, pNode); }
【在 w****x 的大作中提到】 : /* : add sibling pointer to the right sibling of each node in a tree, O(n) time, : O(1) space. : 5 minutes thinking, 10 minutes coding, a hint he gave me: recursion : */ : struct NODE : { : int nVal; : NODE* pLft; : NODE* pRgt;
我也整了个, 请大家提提意见。 public static void connect1(TreeLinkNode root) { if (root==null) return; // index variable for the current level TreeLinkNode curLevNode = root; // scan the tree node level by level while(curLevNode!=null){ // index variable for the next level, // which is used to connect with previous sibling node TreeLinkNode nxtLevPreNode=null;// initialize as null // the first node of the next level, (which will // be passed to connect() for recursive invoke) TreeLinkNode firstNxtLevNode=null; // initialize as null // while scanning all the node in the current level, // connect the nodes in the next level by setting its next field while(curLevNode!=null){ // get the leftChild and rightChild of the current node TreeLinkNode leftChild = curLevNode.left; TreeLinkNode rightChild = curLevNode.right; // if the current node has a leftChild if(leftChild!=null){ // if nxtLevPreNode is null, then the leftChild // would be the first node in the next level if(nxtLevPreNode==null) firstNxtLevNode = leftChild; else// connect with previous sibling node nxtLevPreNode.next = leftChild; // update nxtLevPreNode nxtLevPreNode = leftChild; } // if the current node has a rightChild if (rightChild!=null){ // if nxtLevPreNode is null, then the rightChild // would be the first node in the next level if(nxtLevPreNode==null) firstNxtLevNode = rightChild; else// connect with previous sibling node nxtLevPreNode.next = rightChild; // update nxtLevPreNode nxtLevPreNode = rightChild; } // move the next node of current level curLevNode = curLevNode.next; }// end of while // move to next level curLevNode = firstNxtLevNode; } }
t*y
109 楼
adding a null to the end of each level can be helpful. following is printing out each level. making link list is just same, creating a new list each time a null is Dequeued. Tail null is taken care automatically. public void PrintOutLevel(TreeNode node) { // null,check..... Queue q = new Queue(); q.Enqueue(node); q.Enqueue(null); // This is the tail of the first levle. while (!(q.Count == 0)) { TreeNode tmp = q.Dequeue(); if (tmp == null) { //print out new line... if (!(q.Count == 0)) // make sure the null is not the tail of the last level. { q.Enqueue(null); // tail of the level. } continue; } if (tmp.LeftChild != null) q.Enqueue(tmp.LeftChild); if (tmp.RightChild != null) q.Enqueue(tmp.RightChild); } }
l*a
110 楼
赞。
【在 c****7 的大作中提到】 : 我也整了个, 请大家提提意见。 : public static void connect1(TreeLinkNode root) { : if (root==null) : return; : // index variable for the current level : TreeLinkNode curLevNode = root; : // scan the tree node level by level : while(curLevNode!=null){ : // index variable for the next level, : // which is used to connect with previous sibling node
p*2
111 楼
感觉不复杂,就bfs完了 java版过了OJ public class Solution { public void connect(TreeLinkNode root) { if(root==null) return; TreeLinkNode cur=root; Queue q=new LinkedList(); q.add(cur);