Posts

Showing posts from January 28, 2019

Check whether tree1 has complete structure of tree2

Image
0 $begingroup$ As title described, the code is written to solve the problem. public class Main { public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } public boolean HasSubtree(TreeNode root1,TreeNode root2) { if(root2 == null) { return true; } if(root1 == null) { return false; } if(root1.val == root2.val) { return HasSubtree(root1.left, root2.left) && HasSubtree(root1.right, root2.right); }else { return HasSubtree(root1.left, root2) || HasSubtree(root1.right, root2); } } } The algorithm I used can't pass online judgement, where

Renaming user model

Image
0 I'm following the guide provided in this answer, but I've run into an issue. I'm renaming myauth.MyUser to myauth.User . I created my first set of migrations from other apps, converting every ForeignKey to an IntegerField. The migrations were created fine. I then changed the name or my User model and created a migration, this was also fine. I created my third set of migrations changing the fields back to ForeignKeys to the new model. These migrations also created fine. I then manually added dependencies to the migration files, so that the FK -> Int migrations required the previous version of the user app, and the Int -> FK migrations required the latest, renaming migration. All seems fine, however when I try to run manage.py migrate, I get the following error (a lot of times - for eac