Skip to content

Instantly share code, notes, and snippets.

@czcbangkai
Last active July 17, 2018 05:22
Show Gist options
  • Save czcbangkai/f42db1754b6151e978617d934b27bd09 to your computer and use it in GitHub Desktop.
Save czcbangkai/f42db1754b6151e978617d934b27bd09 to your computer and use it in GitHub Desktop.
╔════════════════╦══════════════════════════════════════════╦══════════════════════════════════════════╗
║ Logic ║ Flip Binary Tree ║ Reverse Singly Linked List ║
╠════════════════╬══════════════════════════════════════════╬══════════════════════════════════════════╣
║ Base Case ║ Root is empty ║ Head is empty ║
║ ║ Root has no left child ║ Head has no next node ║
║ Recursive Call ║ Call root.left to get the final new root ║ Call head.next to get the final new head ║
║ Current Call ║ Let root.left.right point to root ║ Let head.next.next point to head ║
║ ║ Let root.left.left point to root.right ║ ║
║ ║ Let root.left point to NULL ║ Let head.next point to NULL ║
║ ║ Let root.right point to NULL ║ ║
║ Return Value ║ The final new root ║ The final new head ║
╚════════════════╩══════════════════════════════════════════╩══════════════════════════════════════════╝
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment