Created
March 11, 2015 07:58
-
-
Save senarukana/9a02f563278e49d23f58 to your computer and use it in GitHub Desktop.
young matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ef add(self, val): | |
| if self.size >= self.m * self.n: | |
| return False | |
| i, j = self.m-1, self.n-1 | |
| self.mat[i][j] = val | |
| while True: | |
| ni, nj = i, j | |
| if i > 0 and self.mat[i-1][j] > self.mat[ni][nj]: | |
| ni, nj = i-1, j | |
| if j > 0 and self.mat[i][j-1] > self.mat[ni][nj]: | |
| ni, nj = i, j-1 | |
| if ni == i and nj == j: | |
| break | |
| else: | |
| self.mat[i][j], self.mat[ni][nj] = \ | |
| self.mat[ni][nj], self.mat[i][j] | |
| i, j = ni, nj | |
| self.size += 1 | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment