Skip to content

Instantly share code, notes, and snippets.

@lxiange
Last active December 26, 2016 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lxiange/c82450bf82ee5627f86b2eec834e8d64 to your computer and use it in GitHub Desktop.
Save lxiange/c82450bf82ee5627f86b2eec834e8d64 to your computer and use it in GitHub Desktop.
Time Complexity
void foo1(int n) {
int bar = 0;
for (int i = 0; i < n; i++) {
bar++;
}
}
void foo2(int n) {
int sum = 0;
int i = 0;
while (sum < n) {
sum += i++;
}
}
void foo3(int[] arr) {
int bar = 0;
for (int i = 0; i < arr.length; i++) {
bar++;
}
}
void foo4(int[] arr) {
int bar = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i]; j++) {
bar++;
}
}
}
void foo5(char[] arr) {
int num = atoi(arr);
int bar = 0;
for (int i = 0; i < num; i++) {
bar++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment